]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
daemon: Resolve Coverity FORWARD_NULL
authorJohn Ferlan <jferlan@redhat.com>
Fri, 12 Sep 2014 12:40:07 +0000 (08:40 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 15 Sep 2014 15:01:37 +0000 (11:01 -0400)
Coverity complains that the comparison:

  if (nfds && nfds > ((int)!!sock_path + (int)!!sock_path_ro))

could mean 'sock_path' is NULL. Later in virNetSocketNewListenUNIX
there's a direct dereference of path in the error path:

  if (path[0] != '@')

A bit of sleuthing proves that upon entry to daemonSetupNetworking
there is no way for 'sock_path' to be NULL since daemonUnixSocketPaths
will set up 'sock_file' (although it may not set up 'sock_file_ro')
in all 3 paths.

Adjusted code to add ATTRIBUTE_NONNULL(3) on incoming path parameter and
then fixup the comparison of nfds to be a comparison against 2 or 1
depending on whether sock_path_ro is NULL or not.

daemon/libvirtd.c

index 9ad8ff5471447285a779e7635ce3842333b3fb8e..329d8d492b6446bc8bd6cd1d832769d9bcc25fe7 100644 (file)
@@ -442,12 +442,13 @@ static void daemonInitialize(void)
 }
 
 
-static int daemonSetupNetworking(virNetServerPtr srv,
-                                 struct daemonConfig *config,
-                                 const char *sock_path,
-                                 const char *sock_path_ro,
-                                 bool ipsock,
-                                 bool privileged)
+static int ATTRIBUTE_NONNULL(3)
+daemonSetupNetworking(virNetServerPtr srv,
+                      struct daemonConfig *config,
+                      const char *sock_path,
+                      const char *sock_path_ro,
+                      bool ipsock,
+                      bool privileged)
 {
     virNetServerServicePtr svc = NULL;
     virNetServerServicePtr svcRO = NULL;
@@ -467,7 +468,7 @@ static int daemonSetupNetworking(virNetServerPtr srv,
             return -1;
     }
 
-    if (nfds && nfds > ((int)!!sock_path + (int)!!sock_path_ro)) {
+    if (nfds > (sock_path_ro ? 2 : 1)) {
         VIR_ERROR(_("Too many (%u) FDs passed from caller"), nfds);
         return -1;
     }