[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 03/28] 9pfs: remove side-effects in local_open() and
From: |
Greg Kurz |
Subject: |
[Qemu-devel] [PULL 03/28] 9pfs: remove side-effects in local_open() and local_opendir() |
Date: |
Tue, 28 Feb 2017 11:30:15 +0100 |
If these functions fail, they should not change *fs. Let's use local
variables to fix this.
Signed-off-by: Greg Kurz <address@hidden>
Reviewed-by: Stefan Hajnoczi <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 4a8e628117ae..607cd2aeceea 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;
}
--
2.7.4
- [Qemu-devel] [PULL 00/28] 9p CVE-2016-9602 fixes 2017-02-28 for 2.9 soft freeze, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 03/28] 9pfs: remove side-effects in local_open() and local_opendir(),
Greg Kurz <=
- [Qemu-devel] [PULL 01/28] 9pfs: local: move xattr security ops to 9p-xattr.c, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 02/28] 9pfs: remove side-effects in local_init(), Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 05/28] 9pfs: local: keep a file descriptor on the shared folder, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 06/28] 9pfs: local: open/opendir: don't follow symlinks, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 04/28] 9pfs: introduce relative_openat_nofollow() helper, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 09/28] 9pfs: local: lsetxattr: don't follow symlinks, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 07/28] 9pfs: local: lgetxattr: don't follow symlinks, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 08/28] 9pfs: local: llistxattr: don't follow symlinks, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 12/28] 9pfs: local: remove: don't follow symlinks, Greg Kurz, 2017/02/28
- [Qemu-devel] [PULL 13/28] 9pfs: local: utimensat: don't follow symlinks, Greg Kurz, 2017/02/28