Skip to contentSkip to conversation

9pfs: fail local_statfs() earlier

PATCH In review Greg Kurz 4 participants 4 messages Mar 3, 2017

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

PATCH 1/1 9pfs: fail local_statfs() earlier

If we cannot open the given path, we can return right away instead of passing -1 to fstatfs() and close(). This will make Coverity happy.

(Coverity issue CID1371729)

---
 hw/9pfs/9p-local.c |    3 +++
 1 file changed, 3 insertions(+)
hw/9pfs/9p-local.c +3 -0
index fe930300445a..ea9a1ced0394 100644
@@ -1053,6 +1053,9 @@ static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
     int fd, ret;
 
     fd = local_open_nofollow(s, fs_path->data, O_RDONLY, 0);
+    if (fd == -1) {
+        return -1;
+    }
     ret = fstatfs(fd, stbuf);
     close_preserve_errno(fd);
     return ret;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Greg Kurz

If we cannot open the given path, we can return right away instead of passing -1 to fstatfs() and close(). This will make Coverity happy.

(Coverity issue CID1371729)

---
 hw/9pfs/9p-local.c |    3 +++
 1 file changed, 3 insertions(+)
hw/9pfs/9p-local.c +0 -0
index fe930300445a..ea9a1ced0394 100644

hw/9pfs/9p-local.c static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf) · line 1061

Quoted 9 lines
hw/9pfs/9p-local.c +3 -0
@@ -1053,6 +1053,9 @@ static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
     int fd, ret;
 
     fd = local_open_nofollow(s, fs_path->data, O_RDONLY, 0);
+    if (fd == -1) {
+        return -1;
+    }
     ret = fstatfs(fd, stbuf);
     close_preserve_errno(fd);
     return ret;

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|
Reviewed-by on v1 1/1
#2 lore raw
In reply to Greg Kurz
Quoted 9 lines · Greg Kurz

If we cannot open the given path, we can return right away instead of passing -1 to fstatfs() and close(). This will make Coverity happy.

(Coverity issue CID1371729)

---
 hw/9pfs/9p-local.c |    3 +++
 1 file changed, 3 insertions(+)

No difference in end-user observable behavior, but arguably nicer (and always more efficient to avoid unneeded syscalls).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 1/1
#3 lore raw
In reply to Greg Kurz
Quoted 6 lines · Greg Kurz

If we cannot open the given path, we can return right away instead of passing -1 to fstatfs() and close(). This will make Coverity happy.

(Coverity issue CID1371729)

Quoted 20 lines
---
 hw/9pfs/9p-local.c |    3 +++
 1 file changed, 3 insertions(+)
hw/9pfs/9p-local.c +3 -0
index fe930300445a..ea9a1ced0394 100644
@@ -1053,6 +1053,9 @@ static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
     int fd, ret;
 
     fd = local_open_nofollow(s, fs_path->data, O_RDONLY, 0);
+    if (fd == -1) {
+        return -1;
+    }
     ret = fstatfs(fd, stbuf);
     close_preserve_errno(fd);
     return ret;