diff --git a/CHANGES b/CHANGES index 9bd348f2..147eaa35 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ v3.0.3 - YYYY-MMM-DD (to be released) ------------------------------------- + - @ipMatch "Could not add entry" on slash/32 notation in 2.9.0 + [Issue #849 - @zimmerle, @dune73] - Using values after transformation at MATCHED_VARS [0x14316 - @zimmerle] - Adds support to UpdateActionById. diff --git a/Makefile.am b/Makefile.am index 83a94c4a..9c18f0c9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -218,6 +218,7 @@ TESTS+=test/test-cases/regression/variable-ARGS_GET.json TESTS+=test/test-cases/regression/config-update-target-by-msg.json TESTS+=test/test-cases/regression/variable-UNIQUE_ID.json TESTS+=test/test-cases/regression/issue-1528.json +TESTS+=test/test-cases/regression/issue-849.json TESTS+=test/test-cases/regression/variable-REQBODY_PROCESSOR_ERROR.json TESTS+=test/test-cases/regression/operator-detectxss.json TESTS+=test/test-cases/regression/config-update-target-by-tag.json diff --git a/src/utils/msc_tree.cc b/src/utils/msc_tree.cc index 0cbe0cc2..59775f64 100644 --- a/src/utils/msc_tree.cc +++ b/src/utils/msc_tree.cc @@ -846,16 +846,14 @@ TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) { ptr = NULL; return NULL; } - - if(ptr != NULL) { + if (ptr != NULL) { free(ptr); ptr = NULL; } - - if(netmask_v4 == 0) { + if (netmask_v4 == 0) { return NULL; } - else if (netmask_v4 != NETMASK_32 && pos < strlen(ip_strv4)) { + else if (pos < strlen(ip_strv4)) { ip_strv4[pos] = '\0'; } @@ -864,11 +862,9 @@ TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) { if (ret <= 0) { return NULL; } - ip = addr4.s_addr; tree->count++; - return CPTAddElement((unsigned char *)&ip, NETMASK_32, tree, netmask_v4); case IPV6_TREE: @@ -1067,6 +1063,9 @@ unsigned char is_netmask_v4(char *ip_strv4) { } cidr = atoi(mask_str); + if (cidr == 32) { + return 32; + } if ((cidr < 0) || (cidr > 32)) { return 0; } diff --git a/test/test-cases/regression/issue-849.json b/test/test-cases/regression/issue-849.json new file mode 100644 index 00000000..60e0d4e2 --- /dev/null +++ b/test/test-cases/regression/issue-849.json @@ -0,0 +1,96 @@ +[ + { + "enabled": 1, + "version_min": 209000, + "version_max": -1, + "title": "@ipMatch \"Could not add entry\" on slash\/32 notation in 2.9.0 (1/2)", + "url": "https:\/\/github.com\/SpiderLabs\/ModSecurity\/issues\/849", + "client": { + "ip": "200.249.12.31", + "port": 2313 + }, + "server": { + "ip": "200.249.12.31", + "port": 80 + }, + "request": { + "headers": { + "Host": "net.tutsplus.com", + "User-Agent": "", + "Accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8", + "Accept-Language": "en-us,en;q=0.5", + "Accept-Encoding": "gzip,deflate", + "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", + "Keep-Alive": "300", + "Connection": "keep-alive", + "Cookie": "PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120", + "Pragma": "no-cache", + "Cache-Control": "no-cache" + }, + "uri": "\/test.pl?foo=bar", + "method": "GET", + "http_version": 1.1, + "body": "" + }, + "response": { + "headers": { + "Content-Type": "text\/xml; charset=utf-8\n\r", + "Content-Length": "length\n\r" + } + }, + "expected": { + "http_code": 403 + }, + "rules": [ + "SecRuleEngine On", + "SecRule REMOTE_ADDR \"@ipMatch 200.249.12.31\/32\" \"phase:1,nolog,pass,msg:'Localhost connection',id:1,deny,status:403\"" + ] + }, + { + "enabled": 1, + "version_min": 209000, + "version_max": -1, + "title": "@ipMatch \"Could not add entry\" on slash\/32 notation in 2.9.0 (2/2)", + "url": "https:\/\/github.com\/SpiderLabs\/ModSecurity\/issues\/849", + "client": { + "ip": "200.249.12.31", + "port": 2313 + }, + "server": { + "ip": "200.249.12.31", + "port": 80 + }, + "request": { + "headers": { + "Host": "net.tutsplus.com", + "User-Agent": "", + "Accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8", + "Accept-Language": "en-us,en;q=0.5", + "Accept-Encoding": "gzip,deflate", + "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7", + "Keep-Alive": "300", + "Connection": "keep-alive", + "Cookie": "PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120", + "Pragma": "no-cache", + "Cache-Control": "no-cache" + }, + "uri": "\/test.pl?foo=bar", + "method": "GET", + "http_version": 1.1, + "body": "" + }, + "response": { + "headers": { + "Content-Type": "text\/xml; charset=utf-8\n\r", + "Content-Length": "length\n\r" + } + }, + "expected": { + "http_code": 403 + }, + "rules": [ + "SecRuleEngine On", + "SecRule REMOTE_ADDR \"@ipMatch 200.249.12.31\" \"phase:1,nolog,pass,msg:'Localhost connection',id:1,deny,status:403\"" + ] + } +]