summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2015-01-15 15:42:04 +0100
committerLaine Stump <laine@laine.org>2015-04-09 15:30:18 -0400
commitcf2289f2137faad23a0cd663529e9157a5ee4432 (patch)
tree79ecb1bfdbfea2b4fa42708ecb3b2545eabbe772
parentb9dacdd4d992ba1e5aab2e0189cf64b36a1a7e13 (diff)
downloadlibvirt-cf2289f2137faad23a0cd663529e9157a5ee4432.tar.gz
virNetworkDefUpdateIPDHCPHost: Don't crash when updating network
https://bugzilla.redhat.com/show_bug.cgi?id=1182486 When updating a network and adding new ip-dhcp-host entry, the deamon may crash. The problem is, we iterate over existing <host/> entries trying to compare MAC addresses to see if there's already an existing rule. However, not all entries are required to have MAC address. For instance, the following is perfectly valid entry: <host id='00:04:58:fd:e4:15:1b:09:4c:0e:09:af:e4:d3:8c:b8:ca:1e' name='redhatipv6.redhat.com' ip='2001:db8:ca2:2::119'/> When the checking loop iterates over this, the entry's MAC address is accessed directly. Well, the fix is obvious - check if the address is defined before trying to compare it. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> (cherry picked from commit 7d3ae359db604f6052247ad49d7fbce1db7ef99c)
-rw-r--r--src/conf/network_conf.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 57e7cec6b9..cac12c4d47 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -3486,7 +3486,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
/* search for the entry with this (ip|mac|name),
* and update the IP+(mac|name) */
for (i = 0; i < ipdef->nhosts; i++) {
- if ((host.mac &&
+ if ((host.mac && ipdef->hosts[i].mac &&
!virMacAddrCompare(host.mac, ipdef->hosts[i].mac)) ||
(VIR_SOCKET_ADDR_VALID(&host.ip) &&
virSocketAddrEqual(&host.ip, &ipdef->hosts[i].ip)) ||
@@ -3521,7 +3521,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
/* log error if an entry with same name/address/ip already exists */
for (i = 0; i < ipdef->nhosts; i++) {
- if ((host.mac &&
+ if ((host.mac && ipdef->hosts[i].mac &&
!virMacAddrCompare(host.mac, ipdef->hosts[i].mac)) ||
(host.name &&
STREQ_NULLABLE(host.name, ipdef->hosts[i].name)) ||
@@ -3550,7 +3550,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
/* find matching entry - all specified attributes must match */
for (i = 0; i < ipdef->nhosts; i++) {
- if ((!host.mac ||
+ if ((!host.mac || !ipdef->hosts[i].mac ||
!virMacAddrCompare(host.mac, ipdef->hosts[i].mac)) &&
(!host.name ||
STREQ_NULLABLE(host.name, ipdef->hosts[i].name)) &&