]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: set missing data length in virSocketAddrPrefixToNetmask()
authorLaine Stump <laine@laine.org>
Mon, 18 Feb 2019 21:33:57 +0000 (16:33 -0500)
committerLaine Stump <laine@laine.org>
Thu, 21 Feb 2019 17:59:09 +0000 (12:59 -0500)
This fixes a bug that has been present since the original version of
the function was pushed in commit 1ab80f3 on Nov. 26 2010 (by me). The
virSocketAddr::len was not being set.

Apparently until now we were always calling
virSocketAddrPrefixToNetmask with virSocketAddr object that was
already (coincidentally) initialized for the proper address family,
but the bug became apparent when trying to use it to fill in an
otherwise uninitialized object.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/util/virsocketaddr.c

index 4bc14bbd150d8798bdc80511c5642107ce9fb027..ccfaeabe13ba4a702fbccb133a89e11abe63bfcf 100644 (file)
@@ -1032,6 +1032,7 @@ virSocketAddrPrefixToNetmask(unsigned int prefix,
         ip = prefix ? ~((1 << (32 - prefix)) - 1) : 0;
         netmask->data.inet4.sin_addr.s_addr = htonl(ip);
         netmask->data.stor.ss_family = AF_INET;
+        netmask->len = sizeof(struct sockaddr_in);
         result = 0;
 
     } else if (family == AF_INET6) {
@@ -1055,6 +1056,7 @@ virSocketAddrPrefixToNetmask(unsigned int prefix,
             netmask->data.inet6.sin6_addr.s6_addr[i++] = 0;
         }
         netmask->data.stor.ss_family = AF_INET6;
+        netmask->len = sizeof(struct sockaddr_in6);
         result = 0;
     }