[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/29] 9pfs: remove side-effects in local_open() and
From: |
Greg Kurz |
Subject: |
[Qemu-devel] [PATCH 03/29] 9pfs: remove side-effects in local_open() and local_opendir() |
Date: |
Mon, 20 Feb 2017 15:39:42 +0100 |
User-agent: |
StGit/0.17.1-20-gc0b1b-dirty |
If these functions fail, they should not change *fs. Let's use local
variables to fix this.
Signed-off-by: Greg Kurz <address@hidden>
---
hw/9pfs/9p-local.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 55903e5d7745..c2239bfafce4 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -356,10 +356,15 @@ static int local_open(FsContext *ctx, V9fsPath *fs_path,
{
char *buffer;
char *path = fs_path->data;
+ int fd;
buffer = rpath(ctx, path);
- fs->fd = open(buffer, flags | O_NOFOLLOW);
+ fd = open(buffer, flags | O_NOFOLLOW);
g_free(buffer);
+ if (fd == -1) {
+ return -1;
+ }
+ fs->fd = fd;
return fs->fd;
}
@@ -368,13 +373,15 @@ static int local_opendir(FsContext *ctx,
{
char *buffer;
char *path = fs_path->data;
+ DIR *stream;
buffer = rpath(ctx, path);
- fs->dir.stream = opendir(buffer);
+ stream = opendir(buffer);
g_free(buffer);
- if (!fs->dir.stream) {
+ if (!stream) {
return -1;
}
+ fs->dir.stream = stream;
return 0;
}
- [Qemu-devel] [PATCH 00/29] 9pfs: local: fix vulnerability to symlink attacks, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 01/29] 9pfs: local: move xattr security ops to 9p-xattr.c, Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 02/29] 9pfs: remove side-effects in local_init(), Greg Kurz, 2017/02/20
- [Qemu-devel] [PATCH 03/29] 9pfs: remove side-effects in local_open() and local_opendir(),
Greg Kurz <=
- [Qemu-devel] [PATCH 04/29] 9pfs: introduce openat_nofollow() helper, Greg Kurz, 2017/02/20
- Re: [Qemu-devel] [PATCH 04/29] 9pfs: introduce openat_nofollow() helper, Stefan Hajnoczi, 2017/02/23
- Re: [Qemu-devel] [PATCH 04/29] 9pfs: introduce openat_nofollow() helper, Greg Kurz, 2017/02/23
- Re: [Qemu-devel] [PATCH 04/29] 9pfs: introduce openat_nofollow() helper, Stefan Hajnoczi, 2017/02/24
- Re: [Qemu-devel] [PATCH 04/29] 9pfs: introduce openat_nofollow() helper, Greg Kurz, 2017/02/24
- Re: [Qemu-devel] [PATCH 04/29] 9pfs: introduce openat_nofollow() helper, Stefan Hajnoczi, 2017/02/27
- Re: [Qemu-devel] [PATCH 04/29] 9pfs: introduce openat_nofollow() helper, Greg Kurz, 2017/02/27
- [Qemu-devel] [PATCH 05/29] 9pfs: local: keep a file descriptor on the shared folder, Greg Kurz, 2017/02/20