Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed IPv4 address parsing when port is present at end of address #1110

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apache2/msc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,11 @@ int ip_tree_from_uri(TreeRoot **rtree, char *uri,
int tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
const char *value, modsec_rec *msr, char **error_msg)
{
const char *format = "%15[0-9.]:%5[0-9]";
char ip[16] = { 0 }; // ip4 addresses have max len 15
char port[6] = { 0 }; // port numbers are 16bit, ie 5 digits max
struct in_addr in;

#if APR_HAVE_IPV6
struct in6_addr in6;
#endif
Expand All @@ -2705,8 +2709,10 @@ int tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
return 0;
}

if (strchr(value, ':') == NULL) {
if (inet_pton(AF_INET, value, &in) <= 0) {
// test for IPV4 with a port on the end
if (sscanf(value, format, ip, port) == 2) {
//if (strchr(value, ':') == NULL) {
if (inet_pton(AF_INET, ip, &in) <= 0) {
*error_msg = apr_psprintf(mp, "IPmatch: bad IPv4 " \
"specification \"%s\".", value);
return -1;
Expand Down Expand Up @@ -2735,6 +2741,7 @@ int tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
return 0;
}


int ip_tree_from_param(apr_pool_t *mp,
char *param, TreeRoot **rtree, char **error_msg)
{
Expand Down