qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 5/5] monitor: Fix file_completion() to check for stat() failure
Date: Thu, 17 Nov 2011 13:03:38 +0000	[thread overview]
Message-ID: <1321535018-32543-6-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1321535018-32543-1-git-send-email-stefanha@linux.vnet.ibm.com>

From: Markus Armbruster <armbru@redhat.com>

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 <armbru@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 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);
         }
     }
-- 
1.7.7.1

  parent reply	other threads:[~2011-11-17 13:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-17 13:03 [Qemu-devel] [PULL 1.0 0/5] Trivial patches for 11 to 17 November 2011 Stefan Hajnoczi
2011-11-17 13:03 ` [Qemu-devel] [PATCH 1/5] Fix spelling in documentation and comments (similiar -> similar) Stefan Hajnoczi
2011-11-17 13:03 ` [Qemu-devel] [PATCH 2/5] Fix some spelling bugs in documentation and comments Stefan Hajnoczi
2011-11-17 13:03 ` [Qemu-devel] [PATCH 3/5] Fix typo: runnning -> running Stefan Hajnoczi
2011-11-17 13:03 ` [Qemu-devel] [PATCH 4/5] Fixing some spelling in docs/libcacard.txt Stefan Hajnoczi
2011-11-17 13:03 ` Stefan Hajnoczi [this message]
2011-11-22  0:20 ` [Qemu-devel] [PULL 1.0 0/5] Trivial patches for 11 to 17 November 2011 Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1321535018-32543-6-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).