[PATCH 1/5] nss: Compare addresses iff their family matches

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

 



When parsing leases file, appendAddr() is called to append parsed
tuple (address, expiry time, family) into an array. Whilst doing
so, the array is searched for possible duplicate. This is done by
comparing each item of the array by passed @family: if @family is
AF_INET then the item is viewed as IPv4 address. Similarly, if
@family is AF_INET6 then the item is viewed as IPv6 address. This
is not exactly right - the array can contain addresses of both
families and thus the address family of each item of the array
must be considered.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tools/nss/libvirt_nss_leases.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c
index 977e3415f7..e96e260da8 100644
--- a/tools/nss/libvirt_nss_leases.c
+++ b/tools/nss/libvirt_nss_leases.c
@@ -116,14 +116,16 @@ appendAddr(const char *name __attribute__((unused)),
 
     for (i = 0; i < *ntmpAddress; i++) {
         if (family == AF_INET) {
-            if (memcmp((*tmpAddress)[i].addr,
+            if ((*tmpAddress)[i].af == AF_INET &&
+                memcmp((*tmpAddress)[i].addr,
                        &sa.sin.sin_addr,
                        sizeof(sa.sin.sin_addr)) == 0) {
                 DEBUG("IP address already in the list");
                 return 0;
             }
         } else {
-            if (memcmp((*tmpAddress)[i].addr,
+            if ((*tmpAddress)[i].af == AF_INET6 &&
+                memcmp((*tmpAddress)[i].addr,
                        &sa.sin6.sin6_addr,
                        sizeof(sa.sin6.sin6_addr)) == 0) {
                 DEBUG("IP address already in the list");
-- 
2.21.0

--
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]

  Powered by Linux