Blame SOURCES/libvirt-virNetworkDefUpdateIPDHCPHost-Don-t-crash-when-updating-network.patch

9119d9
From 1711b9ad32a5ebc2349ef36e76dc0e3bcae4a6ac Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <1711b9ad32a5ebc2349ef36e76dc0e3bcae4a6ac@dist-git>
9119d9
From: Michal Privoznik <mprivozn@redhat.com>
9119d9
Date: Fri, 16 Jan 2015 10:03:26 +0100
9119d9
Subject: [PATCH] virNetworkDefUpdateIPDHCPHost: Don't crash when updating
9119d9
 network
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1182486
9119d9
9119d9
When updating a network and adding new ip-dhcp-host entry, the deamon
9119d9
may crash. The problem is, we iterate over existing <host/> entries
9119d9
trying to compare MAC addresses to see if there's already an existing
9119d9
rule. However, not all entries are required to have MAC address. For
9119d9
instance, the following is perfectly valid entry:
9119d9
9119d9
9119d9
name='redhatipv6.redhat.com' ip='2001:db8:ca2:2::119'/>
9119d9
9119d9
When the checking loop iterates over this, the entry's MAC address is
9119d9
accessed directly. Well, the fix is obvious - check if the address is
9119d9
defined before trying to compare it.
9119d9
9119d9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9119d9
(cherry picked from commit 7d3ae359db604f6052247ad49d7fbce1db7ef99c)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/conf/network_conf.c | 6 +++---
9119d9
 1 file changed, 3 insertions(+), 3 deletions(-)
9119d9
9119d9
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
9119d9
index 7b19592..73cca4c 100644
9119d9
--- a/src/conf/network_conf.c
9119d9
+++ b/src/conf/network_conf.c
9119d9
@@ -3550,7 +3550,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
9119d9
         /* search for the entry with this (ip|mac|name),
9119d9
          * and update the IP+(mac|name) */
9119d9
         for (i = 0; i < ipdef->nhosts; i++) {
9119d9
-            if ((host.mac &&
9119d9
+            if ((host.mac && ipdef->hosts[i].mac &&
9119d9
                  !virMacAddrCompare(host.mac, ipdef->hosts[i].mac)) ||
9119d9
                 (VIR_SOCKET_ADDR_VALID(&host.ip) &&
9119d9
                  virSocketAddrEqual(&host.ip, &ipdef->hosts[i].ip)) ||
9119d9
@@ -3585,7 +3585,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
9119d9
 
9119d9
         /* log error if an entry with same name/address/ip already exists */
9119d9
         for (i = 0; i < ipdef->nhosts; i++) {
9119d9
-            if ((host.mac &&
9119d9
+            if ((host.mac && ipdef->hosts[i].mac &&
9119d9
                  !virMacAddrCompare(host.mac, ipdef->hosts[i].mac)) ||
9119d9
                 (host.name &&
9119d9
                  STREQ_NULLABLE(host.name, ipdef->hosts[i].name)) ||
9119d9
@@ -3614,7 +3614,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
9119d9
 
9119d9
         /* find matching entry - all specified attributes must match */
9119d9
         for (i = 0; i < ipdef->nhosts; i++) {
9119d9
-            if ((!host.mac ||
9119d9
+            if ((!host.mac || !ipdef->hosts[i].mac ||
9119d9
                  !virMacAddrCompare(host.mac, ipdef->hosts[i].mac)) &&
9119d9
                 (!host.name ||
9119d9
                  STREQ_NULLABLE(host.name, ipdef->hosts[i].name)) &&
9119d9
-- 
9119d9
2.2.1
9119d9