Skip to content

Commit

Permalink
fixed rpaf_looks_like_ip to properly consider IPv6 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffrey McRae committed Sep 2, 2014
1 parent 522b8f4 commit 9e9b483
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions mod_rpaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9e9b483

Please sign in to comment.