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

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