* [Qemu-devel] [PATCH] monitor: Fix file_completion() to check for stat() failure
@ 2011-11-16 14:43 Markus Armbruster
2011-11-18 11:24 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2011-11-16 14:43 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
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>
---
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.6.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] monitor: Fix file_completion() to check for stat() failure
2011-11-16 14:43 [Qemu-devel] [PATCH] monitor: Fix file_completion() to check for stat() failure Markus Armbruster
@ 2011-11-18 11:24 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2011-11-18 11:24 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-trivial, qemu-devel
On Wed, Nov 16, 2011 at 03:43:47PM +0100, Markus Armbruster wrote:
> 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>
> ---
> monitor.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches
I have already sent a pull request including this patch for QEMU 1.0.
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-11-18 11:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-16 14:43 [Qemu-devel] [PATCH] monitor: Fix file_completion() to check for stat() failure Markus Armbruster
2011-11-18 11:24 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
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).