From 9e9b483b226b8f481c71f69469305f4e41d6c467 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 3 Sep 2014 03:19:22 +1000 Subject: [PATCH] fixed rpaf_looks_like_ip to properly consider IPv6 addresses --- mod_rpaf.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/mod_rpaf.c b/mod_rpaf.c index bbe7b14..e259975 100644 --- a/mod_rpaf.c +++ b/mod_rpaf.c @@ -68,10 +68,26 @@ static void *rpaf_create_server_cfg(apr_pool_t *p, server_rec *s) { /* quick check for ipv4/6 likelihood; similar to Apache2.4 mod_remoteip check */ static int rpaf_looks_like_ip(const char *ip) { - const char *ptr = ip; + static const char ipv4_set[] = "0123456789./"; + static const char ipv6_set[] = "0123456789abcdef:/"; - while (*ptr == '.' || *ptr == ':' || *ptr == '/' || isdigit(*ptr)) - ptr++; + /* zero length value is not valid */ + if (!*ip) + return 0; + + const char *ptr = ip; + + /* determine if this could be a IPv6 or IPv4 address */ + if (strchr(ip, ':')) + { + while(*ptr && strchr(ipv6_set, *ptr) != NULL) + ++ptr; + } + else + { + while(*ptr && strchr(ipv4_set, *ptr) != NULL) + ++ptr; + } return (*ptr == '\0'); } @@ -99,6 +115,11 @@ static const char *rpaf_set_proxy_ip(cmd_parms *cmd, void *dummy, const char *pr cmd->cmd->name, ". ", msgbuf, NULL); } } + else + { + return apr_pstrcat(cmd->pool, "mod_rpaf: Error parsing IP \"", proxy_ip, "\" in ", + cmd->cmd->name, ". Failed basic parsing.", NULL); + } return NULL; }