]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virt-login-shell: silence coverity warning
authorEric Blake <eblake@redhat.com>
Wed, 5 Mar 2014 18:55:27 +0000 (11:55 -0700)
committerEric Blake <eblake@redhat.com>
Wed, 5 Mar 2014 18:59:06 +0000 (11:59 -0700)
Coverity spotted that 'nfdlist' (ssize_t) could be -1, but that we
were using 'i' (size_t) to iterate over the list at cleanup, with
crashing results because it promotes to a really big unsigned number.

* tools/virt-login-shell.c (main): Avoid treating -1 as unsigned.

Signed-off-by: Eric Blake <eblake@redhat.com>
tools/virt-login-shell.c

index 3ea7ade4bed80047b174c5e9f417638172edff13..abe7eebdf72eef98815626618c31d3e38d1c98e8 100644 (file)
@@ -339,8 +339,9 @@ main(int argc, char **argv)
     /* At this point, the parent is now waiting for the child to exit,
      * but as that may take a long time, we release resources now.  */
 cleanup:
-    for (i = 0; i < nfdlist; i++)
-        VIR_FORCE_CLOSE(fdlist[i]);
+    if (nfdlist > 0)
+        for (i = 0; i < nfdlist; i++)
+            VIR_FORCE_CLOSE(fdlist[i]);
     VIR_FREE(fdlist);
     virConfFree(conf);
     if (dom)