]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nss: Need to check error condition on virJSONValueArraySize
authorJohn Ferlan <jferlan@redhat.com>
Wed, 7 Dec 2016 13:10:30 +0000 (08:10 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 8 Dec 2016 19:58:31 +0000 (14:58 -0500)
If the 'nleases < 0' on return, then the subsequent call to
findLeaseInJSON will not produce the expected results (passed
in as a size_t, but nleases is a ssize_t).  So check if the
returned value < 0 and if so, goto cleanup.

Found by Coverity as a NEGATIVE_RETURNS event

tools/nss/libvirt_nss.c

index 418c11fafe101b006b47736a57879c65a6e70d42..b69e62c8b19a79014aa270a21478844e8cb6949e 100644 (file)
@@ -309,7 +309,8 @@ findLease(const char *name,
     }
     VIR_DIR_CLOSE(dir);
 
-    nleases = virJSONValueArraySize(leases_array);
+    if ((nleases = virJSONValueArraySize(leases_array)) < 0)
+        goto cleanup;
     DEBUG("Read %zd leases", nleases);
 
 #if !defined(LIBVIRT_NSS_GUEST)