From patchwork Wed Nov 16 14:43:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 125993 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D449AB6FF5 for ; Thu, 17 Nov 2011 01:44:09 +1100 (EST) Received: from localhost ([::1]:43400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQgia-00028f-Hp for incoming@patchwork.ozlabs.org; Wed, 16 Nov 2011 09:44:04 -0500 Received: from eggs.gnu.org ([140.186.70.92]:47406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQgiO-00028G-KT for qemu-devel@nongnu.org; Wed, 16 Nov 2011 09:44:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RQgiN-0002du-KO for qemu-devel@nongnu.org; Wed, 16 Nov 2011 09:43:52 -0500 Received: from oxygen.pond.sub.org ([78.46.104.156]:54971) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQgiN-0002dQ-Fl; Wed, 16 Nov 2011 09:43:51 -0500 Received: from blackfin.pond.sub.org (p5B32D5E5.dip.t-dialin.net [91.50.213.229]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 85C7CA22CD; Wed, 16 Nov 2011 15:43:48 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id D96CD6006E; Wed, 16 Nov 2011 15:43:47 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 16 Nov 2011 15:43:47 +0100 Message-Id: <1321454627-19403-1-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.6.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: qemu-trivial@nongnu.org Subject: [Qemu-devel] [PATCH] monitor: Fix file_completion() to check for stat() failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org stat() can fail for a file name just read with readdir(). Easiest way to trigger is a dangling symbolic link --- look ma, no race! When it fails, file_completion() uses sb.st_mode uninitialized. If the directory bit happens to be set, it appends a "/" to the completed name. Signed-off-by: Markus Armbruster --- monitor.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index 5ea35de..1be222e 100644 --- a/monitor.c +++ b/monitor.c @@ -4207,9 +4207,9 @@ static void file_completion(const char *input) /* stat the file to find out if it's a directory. * In that case add a slash to speed up typing long paths */ - stat(file, &sb); - if(S_ISDIR(sb.st_mode)) + if (stat(file, &sb) == 0 && S_ISDIR(sb.st_mode)) { pstrcat(file, sizeof(file), "/"); + } readline_add_completion(cur_mon->rs, file); } }