]> xenbits.xensource.com Git - libvirt.git/commitdiff
phyp: Fix NULL dereference in phypConnectOpen
authorMartin Kletzander <mkletzan@redhat.com>
Fri, 7 Nov 2014 18:52:33 +0000 (19:52 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 11 Nov 2014 07:23:09 +0000 (08:23 +0100)
Coverity found out that commit cd490086 caused a possible NULL pointer
dereference.  This is due to the fact, that phyp_driver is NULL at the
time of closing the socket, instead of connection_data, which kept the
socket before the mentioned commit, could not be NULL.

However, internal_socket is still the local socket that can be
closed, even unconditionally, if we initialize it to -1.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/phyp/phyp_driver.c

index 7c8bc5c23751a4986acedb9b9dca055e613b7c97..386d25f85507b613076217f0bf94131dc8b96d3f 100644 (file)
@@ -1128,7 +1128,7 @@ phypConnectOpen(virConnectPtr conn,
                 virConnectAuthPtr auth, unsigned int flags)
 {
     LIBSSH2_SESSION *session = NULL;
-    int internal_socket;
+    int internal_socket = -1;
     uuid_tablePtr uuid_table = NULL;
     phyp_driverPtr phyp_driver = NULL;
     char *char_ptr;
@@ -1232,7 +1232,7 @@ phypConnectOpen(virConnectPtr conn,
         libssh2_session_free(session);
     }
 
-    VIR_FORCE_CLOSE(phyp_driver->sock);
+    VIR_FORCE_CLOSE(internal_socket);
 
     return VIR_DRV_OPEN_ERROR;
 }