Blame SOURCES/net-snmp-5.8-double-IP-parsing.patch

77be88
From 1bb941d6fcd7ac2db5a54b95ee0ed07ec9861e70 Mon Sep 17 00:00:00 2001
77be88
From: =?UTF-8?q?Josef=20=C5=98=C3=ADdk=C3=BD?= <jridky@redhat.com>
77be88
Date: Fri, 12 Mar 2021 10:15:30 +0100
77be88
Subject: [PATCH] Prevent parsing IP address twice (#199)
77be88
77be88
This fixes issue, that is caused by parsing IP address twice.
77be88
First as IPv4 and as IPv6 at second, even thow the address was
77be88
properly parsed as a valid IPv4 address.
77be88
---
77be88
 snmplib/transports/snmpUDPDomain.c     |  2 +-
77be88
 snmplib/transports/snmpUDPIPv6Domain.c | 10 +++++++++-
77be88
 2 files changed, 10 insertions(+), 2 deletions(-)
77be88
77be88
diff --git a/snmplib/transports/snmpUDPDomain.c b/snmplib/transports/snmpUDPDomain.c
77be88
index b96497f3a3..b594a389b9 100644
77be88
--- a/snmplib/transports/snmpUDPDomain.c
77be88
+++ b/snmplib/transports/snmpUDPDomain.c
77be88
@@ -387,7 +387,7 @@ netsnmp_udp_parse_security(const char *token, char *param)
77be88
             /* Nope, wasn't a dotted quad.  Must be a hostname. */
77be88
             int ret = netsnmp_gethostbyname_v4(sourcep, &network.s_addr);
77be88
             if (ret < 0) {
77be88
-                config_perror("cannot resolve source hostname");
77be88
+                config_perror("cannot resolve IPv4 source hostname");
77be88
                 return;
77be88
             }
77be88
         }
77be88
diff --git a/snmplib/transports/snmpUDPIPv6Domain.c b/snmplib/transports/snmpUDPIPv6Domain.c
77be88
index 238c8a9d63..7db19c5c02 100644
77be88
--- a/snmplib/transports/snmpUDPIPv6Domain.c
77be88
+++ b/snmplib/transports/snmpUDPIPv6Domain.c
77be88
@@ -736,7 +736,15 @@ netsnmp_udp6_parse_security(const char *token, char *param)
77be88
                 memset(&pton_addr.sin6_addr.s6_addr, '\0',
77be88
                        sizeof(struct in6_addr));
77be88
             } else if (inet_pton(AF_INET6, sourcep, &pton_addr.sin6_addr) != 1) {
77be88
-                /* Nope, wasn't a numeric address. Must be a hostname. */
77be88
+                /* Nope, wasn't a numeric IPv6 address. Must be IPv4 or a hostname. */
77be88
+
77be88
+                /* Try interpreting as dotted quad - IPv4 */
77be88
+                struct in_addr network;
77be88
+                if (inet_pton(AF_INET, sourcep, &network) > 0){
77be88
+                    /* Yes, it's IPv4 - so it's already parsed and we can return. */
77be88
+                    DEBUGMSGTL(("com2sec6", "IPv4 detected for IPv6 parser. Skipping.\n"));
77be88
+                    return;
77be88
+                }
77be88
 #if HAVE_GETADDRINFO
77be88
                 int             gai_error;
77be88
 
77be88