Skip to content

Commit beedddd

Browse files
author
Felipe Zimmerle
committed
Fix @pm lookup for possible matches on offset zero
1 parent d5b93c1 commit beedddd

File tree

4 files changed

+156
-4
lines changed

4 files changed

+156
-4
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.0.4 - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Fix @pm lookup for possible matches on offset zero.
5+
[@zimmerle, @afoxdavidi, @martinhsv, @marshal09]
46
- Regex lookup on the key name instead of COLLECTION:key
57
[@rdiperri-yottaa, @danbiagini-work, @mmelo-yottaa, @zimmerle]
68
- Missing throw in Operator::instantiate

src/operators/pm.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void Pm::postOrderTraversal(acmp_btree_node_t *node) {
8484

8585
bool Pm::evaluate(Transaction *transaction, Rule *rule,
8686
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
87-
int rc = 0;
87+
int rc = -1;
8888
ACMPT pt;
8989
pt.parser = m_p;
9090
pt.ptr = NULL;
@@ -97,7 +97,7 @@ bool Pm::evaluate(Transaction *transaction, Rule *rule,
9797
pthread_mutex_unlock(&m_lock);
9898
#endif
9999

100-
if (rc > 0 && transaction) {
100+
if (rc >= 0 && transaction) {
101101
std::string match_(match);
102102
logOffset(ruleMessage, rc - match_.size() + 1, match_.size());
103103
transaction->m_matched.push_back(match_);
@@ -110,7 +110,7 @@ bool Pm::evaluate(Transaction *transaction, Rule *rule,
110110
std::string(match));
111111
}
112112

113-
return rc > 0;
113+
return rc >= 0;
114114
}
115115

116116

src/utils/acmp.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ int acmp_process_quick(ACMPT *acmpt, const char **match, const char *data, size_
585585
offset++;
586586
}
587587
acmpt->ptr = node;
588-
return 0;
588+
return -1;
589589
}
590590

591591
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
[
2+
{
3+
"enabled": 1,
4+
"version_min": 300000,
5+
"version_max": 0,
6+
"title": "pm operator test 1/4",
7+
"client": {
8+
"ip": "200.249.12.31",
9+
"port": 2313
10+
},
11+
"server": {
12+
"ip": "200.249.12.31",
13+
"port": 80
14+
},
15+
"request": {
16+
"headers": {
17+
"Host": "net.tutsplus.com"
18+
},
19+
"uri": "\/test.pl?param1=something`somenthing",
20+
"method": "GET",
21+
"http_version": 1.1,
22+
"body": ""
23+
},
24+
"response": {
25+
"headers": {
26+
"Content-Type": "text\/xml; charset=utf-8\n\r",
27+
"Content-Length": "length\n\r"
28+
}
29+
},
30+
"expected": {
31+
"debug_log": "Rule returned 1",
32+
"http_code": 500
33+
},
34+
"rules": [
35+
"SecRuleEngine On",
36+
"SecRule ARGS \"@pm a ` b\" \"phase:1,id:999,deny,status:500\""
37+
]
38+
},
39+
{
40+
"enabled": 1,
41+
"version_min": 300000,
42+
"version_max": 0,
43+
"title": "pm operater test 2/4",
44+
"client": {
45+
"ip": "200.249.12.31",
46+
"port": 2313
47+
},
48+
"server": {
49+
"ip": "200.249.12.31",
50+
"port": 80
51+
},
52+
"request": {
53+
"headers": {
54+
"Host": "net.tutsplus.com"
55+
},
56+
"uri": "\/test.pl?param1=`somenthing",
57+
"method": "GET",
58+
"http_version": 1.1,
59+
"body": ""
60+
},
61+
"response": {
62+
"headers": {
63+
"Content-Type": "text\/xml; charset=utf-8\n\r",
64+
"Content-Length": "length\n\r"
65+
}
66+
},
67+
"expected": {
68+
"debug_log": "",
69+
"http_code": 500
70+
},
71+
"rules": [
72+
"SecRuleEngine On",
73+
"SecRule ARGS \"@pm a ` b\" \"phase:1,id:999,deny,status:500\""
74+
]
75+
},
76+
{
77+
"enabled": 1,
78+
"version_min": 300000,
79+
"version_max": 0,
80+
"title": "pm operater test 3/4",
81+
"client": {
82+
"ip": "200.249.12.31",
83+
"port": 2313
84+
},
85+
"server": {
86+
"ip": "200.249.12.31",
87+
"port": 80
88+
},
89+
"request": {
90+
"headers": {
91+
"Host": "net.tutsplus.com"
92+
},
93+
"uri": "\/test.pl?param1=a",
94+
"method": "GET",
95+
"http_version": 1.1,
96+
"body": ""
97+
},
98+
"response": {
99+
"headers": {
100+
"Content-Type": "text\/xml; charset=utf-8\n\r",
101+
"Content-Length": "length\n\r"
102+
}
103+
},
104+
"expected": {
105+
"debug_log": "Rule returned 1",
106+
"http_code": 500
107+
},
108+
"rules": [
109+
"SecRuleEngine On",
110+
"SecRule ARGS \"@pm a ` b\" \"phase:1,id:999,deny,status:500\""
111+
]
112+
},
113+
{
114+
"enabled": 1,
115+
"version_min": 300000,
116+
"version_max": 0,
117+
"title": "pm operater test 4/4",
118+
"client": {
119+
"ip": "200.249.12.31",
120+
"port": 2313
121+
},
122+
"server": {
123+
"ip": "200.249.12.31",
124+
"port": 80
125+
},
126+
"request": {
127+
"headers": {
128+
"Host": "net.tutsplus.com"
129+
},
130+
"uri": "\/test.pl?param1=a`b",
131+
"method": "GET",
132+
"http_version": 1.1,
133+
"body": ""
134+
},
135+
"response": {
136+
"headers": {
137+
"Content-Type": "text\/xml; charset=utf-8\n\r",
138+
"Content-Length": "length\n\r"
139+
}
140+
},
141+
"expected": {
142+
"debug_log": "Rule returned 1",
143+
"http_code": 500
144+
},
145+
"rules": [
146+
"SecRuleEngine On",
147+
"SecRule ARGS \"@pm a ` b\" \"phase:1,id:999,deny,status:500\""
148+
]
149+
}
150+
]

0 commit comments

Comments
 (0)