]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: netdev: Don't crash in virNetDevSetIPAddress if @peer is NULL
authorPeter Krempa <pkrempa@redhat.com>
Fri, 8 Apr 2016 11:51:57 +0000 (13:51 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 8 Apr 2016 12:28:11 +0000 (14:28 +0200)
VIR_SOCKET_ADDR_VALID dereferences the pointer, thus if we pass NULL
into virNetDevSetIPAddress it crashes. Regression introduced by
b3d069872ce53eb.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1325120

src/util/virnetdev.c

index 712c3bcc32c49c13867707449d6ae78fc16755c7..a505b6c0b6278b82f1dbd7fe0d15400c20625768 100644 (file)
@@ -1129,7 +1129,7 @@ int virNetDevSetIPAddress(const char *ifname,
     unsigned int recvbuflen;
 
     /* The caller needs to provide a correct address */
-    if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET && !VIR_SOCKET_ADDR_VALID(peer)) {
+    if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET && peer && !VIR_SOCKET_ADDR_VALID(peer)) {
         /* compute a broadcast address if this is IPv4 */
         if (VIR_ALLOC(broadcast) < 0)
             return -1;
@@ -1445,7 +1445,7 @@ int virNetDevSetIPAddress(const char *ifname,
     if (!(addrstr = virSocketAddrFormat(addr)))
         goto cleanup;
 
-    if (VIR_SOCKET_ADDR_VALID(peer) && !(peerstr = virSocketAddrFormat(peer)))
+    if (peer && VIR_SOCKET_ADDR_VALID(peer) && !(peerstr = virSocketAddrFormat(peer)))
         goto cleanup;
 
     /* format up a broadcast address if this is IPv4 */