[Openvpn-devel,v2] socket_util: check the address family in addrlist_match()

Message ID 20261118163009.22733-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] socket_util: check the address family in addrlist_match() |

Commit Message

Gert Doering Nov. 18, 2026, 4:30 p.m. UTC
  From: Razvan Cojocaru <razvanc@mailbox.org>

addrlist_match() cast each remote list entry to the peer's address
family without checking ai_family. With a dual-stack remote list, an
IPv6 peer compared against an IPv4 entry read past the end of its
sockaddr_in, and 0.0.0.0 matched any IPv6 entry. Skip entries of the
other family, as addrlist_port_match() already does.

Change-Id: Ic3efcdb7bc4e60a81b9292adfe7f8e22b86e274a
Signed-off-by: Razvan Cojocaru <razvanc@mailbox.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2215
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2215
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
  

Patch

diff --git a/src/openvpn/socket_util.h b/src/openvpn/socket_util.h
index a1a61af..e85f6fe 100644
--- a/src/openvpn/socket_util.h
+++ b/src/openvpn/socket_util.h
@@ -312,6 +312,10 @@ 
     const struct addrinfo *curele;
     for (curele = addrlist; curele; curele = curele->ai_next)
     {
+        if (a1->addr.sa.sa_family != curele->ai_family)
+        {
+            continue;
+        }
         switch (a1->addr.sa.sa_family)
         {
             case AF_INET: