[PATCH 06/28] util: allow calling virSocketAddrGetIPPrefix with NULL netmask or address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There are times when we don't have a netmask pointer to give to
virSocketAddrGetIPPrefix() (e.g. the IP addresses in domain interfaces
only have a prefix, no netmask), but it would have caused a segv if we
called it with NULL instead of a pointer to a netmask. This patch
qualifies the code that would use the netmask or address pointers to
check for NULL first.
---
 src/util/virsocketaddr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 12fe96a..33b1e9e 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2015 Red Hat, Inc.
+ * Copyright (C) 2009-2016 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1026,9 +1026,9 @@ virSocketAddrGetIPPrefix(const virSocketAddr *address,
 {
     if (prefix > 0) {
         return prefix;
-    } else if (VIR_SOCKET_ADDR_VALID(netmask)) {
+    } else if (netmask && VIR_SOCKET_ADDR_VALID(netmask)) {
         return virSocketAddrGetNumNetmaskBits(netmask);
-    } else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET)) {
+    } else if (address && VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET)) {
         /* Return the natural prefix for the network's ip address.
          * On Linux we could use the IN_CLASSx() macros, but those
          * aren't guaranteed on all platforms, so we just deal with
@@ -1053,7 +1053,7 @@ virSocketAddrGetIPPrefix(const virSocketAddr *address,
             return 24;
         }
         return -1;
-    } else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6)) {
+    } else if (address && VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6)) {
         if (virSocketAddrIsWildcard(address))
             return 0;
         return 64;
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]