[Qemu-devel] [PATCH] 9pfs: fix bogus fd check in local_remove()

Greg Kurz posted 1 patch 7 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/148855786023.23661.6584039229850547004.stgit@bahia
Test checkpatch passed
Test docker passed
Test s390x failed
hw/9pfs/9p-local.c |    2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Qemu-devel] [PATCH] 9pfs: fix bogus fd check in local_remove()
Posted by Greg Kurz 7 years, 1 month ago
This was spotted by Coverity as a fd leak. This is certainly true, but also
local_remove() would always return without doing anything, unless the fd is
zero, which is very unlikely.

(Coverity issue CID1371732)

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/9pfs/9p-local.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index f22a3c3654db..5db7104334d6 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -1008,7 +1008,7 @@ static int local_remove(FsContext *ctx, const char *path)
     int err = -1;
 
     dirfd = local_opendir_nofollow(ctx, dirpath);
-    if (dirfd) {
+    if (dirfd == -1) {
         goto out;
     }
 


Re: [Qemu-devel] [PATCH] 9pfs: fix bogus fd check in local_remove()
Posted by Eric Blake 7 years, 1 month ago
On 03/03/2017 10:17 AM, Greg Kurz wrote:
> This was spotted by Coverity as a fd leak. This is certainly true, but also
> local_remove() would always return without doing anything, unless the fd is
> zero, which is very unlikely.
> 
> (Coverity issue CID1371732)
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
>  hw/9pfs/9p-local.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

> diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
> index f22a3c3654db..5db7104334d6 100644
> --- a/hw/9pfs/9p-local.c
> +++ b/hw/9pfs/9p-local.c
> @@ -1008,7 +1008,7 @@ static int local_remove(FsContext *ctx, const char *path)
>      int err = -1;
>  
>      dirfd = local_opendir_nofollow(ctx, dirpath);
> -    if (dirfd) {
> +    if (dirfd == -1) {
>          goto out;
>      }
>  
> 
> 
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org