提交 243b7814 编写于 作者: E Eric Blake

network: plug unininitialized read found by valgrind

* src/util/network.c (virSocketAddrMask): Zero out port, so that
iptables can initialize just the netmask then call
virSocketFormatAddr without an uninitialized read in getnameinfo.
上级 718a8dc6
/* /*
* network.c: network helper APIs for libvirt * network.c: network helper APIs for libvirt
* *
* Copyright (C) 2009-2010 Red Hat, Inc. * Copyright (C) 2009-2011 Red Hat, Inc.
* *
* See COPYING.LIB for the License of this software * See COPYING.LIB for the License of this software
* *
...@@ -291,6 +291,7 @@ int virSocketAddrIsNetmask(virSocketAddrPtr netmask) { ...@@ -291,6 +291,7 @@ int virSocketAddrIsNetmask(virSocketAddrPtr netmask) {
* virSocketAddrMask: * virSocketAddrMask:
* @addr: address that needs to be masked * @addr: address that needs to be masked
* @netmask: the netmask address * @netmask: the netmask address
* @network: where to store the result, can be same as @addr
* *
* Mask off the host bits of @addr according to @netmask, turning it * Mask off the host bits of @addr according to @netmask, turning it
* into a network address. * into a network address.
...@@ -311,6 +312,7 @@ virSocketAddrMask(const virSocketAddrPtr addr, ...@@ -311,6 +312,7 @@ virSocketAddrMask(const virSocketAddrPtr addr,
network->data.inet4.sin_addr.s_addr network->data.inet4.sin_addr.s_addr
= (addr->data.inet4.sin_addr.s_addr = (addr->data.inet4.sin_addr.s_addr
& netmask->data.inet4.sin_addr.s_addr); & netmask->data.inet4.sin_addr.s_addr);
network->data.inet4.sin_port = 0;
network->data.stor.ss_family = AF_INET; network->data.stor.ss_family = AF_INET;
network->len = addr->len; network->len = addr->len;
return 0; return 0;
...@@ -322,6 +324,7 @@ virSocketAddrMask(const virSocketAddrPtr addr, ...@@ -322,6 +324,7 @@ virSocketAddrMask(const virSocketAddrPtr addr,
= (addr->data.inet6.sin6_addr.s6_addr[ii] = (addr->data.inet6.sin6_addr.s6_addr[ii]
& netmask->data.inet6.sin6_addr.s6_addr[ii]); & netmask->data.inet6.sin6_addr.s6_addr[ii]);
} }
network->data.inet6.sin6_port = 0;
network->data.stor.ss_family = AF_INET6; network->data.stor.ss_family = AF_INET6;
network->len = addr->len; network->len = addr->len;
return 0; return 0;
...@@ -334,6 +337,7 @@ virSocketAddrMask(const virSocketAddrPtr addr, ...@@ -334,6 +337,7 @@ virSocketAddrMask(const virSocketAddrPtr addr,
* virSocketAddrMaskByPrefix: * virSocketAddrMaskByPrefix:
* @addr: address that needs to be masked * @addr: address that needs to be masked
* @prefix: prefix (# of 1 bits) of netmask to apply * @prefix: prefix (# of 1 bits) of netmask to apply
* @network: where to store the result, can be same as @addr
* *
* Mask off the host bits of @addr according to @prefix, turning it * Mask off the host bits of @addr according to @prefix, turning it
* into a network address. * into a network address.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册