From 28ddf48899fad28bd21f7f187c0eb305ae105b8a Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 11 Dec 2017 18:18:28 +0100 Subject: [PATCH] mingw: improve ipaddress parsing --- src/win32-misc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/win32-misc.c b/src/win32-misc.c index 80eb29cd62..ed52eb5b7a 100644 --- a/src/win32-misc.c +++ b/src/win32-misc.c @@ -28,6 +28,7 @@ #include "suricata-common.h" #include "win32-misc.h" #include "direct.h" +#include "util-ip.h" void setenv(const char *name, const char *value, int overwrite) { @@ -80,6 +81,17 @@ int inet_pton(int af, const char *src, void *dst) memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = af; + /* as getaddrinfo below seems more liberal that inet_pton on Linux, + * add this check here that does a guess at the validity of the + * input address. */ + if (af == AF_INET) { + if (!IPv4AddressStringIsValid(src)) + return -1; + } else if (af == AF_INET6) { + if (!IPv6AddressStringIsValid(src)) + return -1; + } + struct addrinfo* result = NULL; if (0 != getaddrinfo(src, NULL, &hints, &result)) return -1; -- 2.47.2