emacs-diffs
[Top][All Lists]
Advanced

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

master d8e8e1d5ed2 1/2: Fix network test failure when using VPN client


From: Robert Pluim
Subject: master d8e8e1d5ed2 1/2: Fix network test failure when using VPN client
Date: Thu, 19 Dec 2024 10:29:29 -0500 (EST)

branch: master
commit d8e8e1d5ed260222e2630141d26572a361a5c75f
Author: Robert Pluim <rpluim@gmail.com>
Commit: Robert Pluim <rpluim@gmail.com>

    Fix network test failure when using VPN client
    
    When using certain VPN clients, the interface info returned by
    'getifaddrs' does not have the address family filled in for the
    ifa_netmask component (this is allowed by the standard, since
    the value is not specified).  The resulting address info causes
    network tests suite failures.  Fix by copying the address family
    from the returned interface address.
    
    * src/process.c (network_interface_list): Copy the interface address
    sa_family to the netmask address.
    (Fnetwork_lookup_address_info): Fix test for non-IP addresses to
    properly account for IPv6.
    
    * test/src/process-tests.el (process-tests-check-bug-74907): New
    test, checks that 'network-interface-list' output is as
    expected.
    
    (Bug#74907)
---
 src/process.c             | 20 ++++++++++++++------
 test/src/process-tests.el | 11 +++++++++++
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/src/process.c b/src/process.c
index cd1378f07ad..4b3178005c8 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4351,6 +4351,10 @@ network_interface_list (bool full, unsigned short match)
 
       if (full)
         {
+         /* Sometimes sa_family is only filled in correctly in the
+            interface address, not the netmask, so copy it across
+            (Bug#74907).  */
+         it->ifa_netmask->sa_family = it->ifa_addr->sa_family;
           elt = Fcons (conv_sockaddr_to_lisp (it->ifa_netmask, len), elt);
           /* There is an it->ifa_broadaddr field, but its contents are
              unreliable, so always calculate the broadcast address from
@@ -4764,13 +4768,17 @@ returned from the lookup.  */)
     {
       for (lres = res; lres; lres = lres->ai_next)
         {
-#ifndef AF_INET6
-          if (lres->ai_family != AF_INET)
-            continue;
+         /* Avoid converting non-IP addresses (Bug#74907).  */
+         if (lres->ai_family == AF_INET
+#ifdef AF_INET6
+             || lres->ai_family == AF_INET6
 #endif
-          addresses = Fcons (conv_sockaddr_to_lisp (lres->ai_addr,
-                                                    lres->ai_addrlen),
-                             addresses);
+             )
+           addresses = Fcons (conv_sockaddr_to_lisp (lres->ai_addr,
+                                                     lres->ai_addrlen),
+                              addresses);
+         else
+           continue;
         }
       addresses = Fnreverse (addresses);
 
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index 98bdbbd42ee..88a622e5952 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -519,6 +519,17 @@ See Bug#30460."
 
 ;; End of tests requiring DNS
 
+(ert-deftest process-tests-check-bug-74907 ()
+  "Check that the result of `network-interface-list' is well-formed.
+(Bug#74907)"
+  (dolist (info (network-interface-list t))
+    (should (stringp (car info)))
+    (should (length= info 4))
+    (should (cl-every #'vectorp (cdr info)))
+    (let ((alen (length (cadr info))))
+      (should (memq alen '(5 9)))       ; Address info also has a port number
+      (should (cl-every (lambda (elt) (length= elt alen)) (cdr info))))))
+
 (defmacro process-tests--ignore-EMFILE (&rest body)
   "Evaluate BODY, ignoring EMFILE errors."
   (declare (indent 0) (debug t))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]