Skip to content

Commit 135d1fa

Browse files
authored
Merge pull request #2985 from martinhsv/v3/master
Fix: lmdb regex match on non-null-terminated string
2 parents 375519d + af45ccd commit 135d1fa

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

CHANGES

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

4+
- Fix: lmdb regex match on non-null terminated string
5+
[Issue #2985 - @martinhsv]
46
- Fix memory leaks in lmdb code (new'd strings)
57
[Issue #2983 - @martinhsv]
68
- Configure: add additional name to pcre2 pkg-config list

src/collection/backend/lmdb.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,11 @@ void LMDB::resolveRegularExpression(const std::string& var,
473473
}
474474

475475
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
476-
char *a = reinterpret_cast<char *>(key.mv_data);
477-
int ret = Utils::regex_search(a, r);
476+
std::string key_to_insert(reinterpret_cast<char *>(key.mv_data), key.mv_size);
477+
int ret = Utils::regex_search(key_to_insert, r);
478478
if (ret <= 0) {
479479
continue;
480480
}
481-
std::string key_to_insert(reinterpret_cast<char *>(key.mv_data), key.mv_size);
482481
if (ke.toOmit(key_to_insert)) {
483482
continue;
484483
}

test/test-cases/regression/collection-regular_expression_selection.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Pragma":"no-cache",
2626
"Cache-Control":"no-cache"
2727
},
28-
"uri":"\/test.pl?id_a= test &id_b=test2&nah=nops",
28+
"uri":"\/test.pl?id_a=test&nah=nops",
2929
"method":"GET",
3030
"http_version":1.1,
3131
"body":""
@@ -48,12 +48,15 @@
4848
},
4949
"expected":{
5050
"audit_log":"",
51-
"debug_log":"T \\(0\\) t:lowercase: \"test2\"",
52-
"error_log":""
51+
"debug_log":"Saving variable: IP:nah with value: nops",
52+
"error_log":"",
53+
"http_code":200
5354
},
5455
"rules":[
5556
"SecRuleEngine On",
56-
"SecRule ARGS:/^id_/ \"@contains nops\" \"id:1,t:lowercase,block,status:404\""
57+
"SecRule ARGS:/^id_/ \"@contains test\" \"id:1,phase:2,t:lowercase,initcol:ip=%{REMOTE_ADDR}\"",
58+
"SecRule ARGS:/^id_/ \"@contains test\" \"id:2,phase:2,t:lowercase,setvar:IP.nah=nops\"",
59+
"SecRule IP:/id_a$/ \"rx .\" \"id:3,phase:2,deny,status:403\""
5760
]
5861
},
5962
{
@@ -82,7 +85,7 @@
8285
"Pragma":"no-cache",
8386
"Cache-Control":"no-cache"
8487
},
85-
"uri":"\/test.pl?id_a= test &id_b=test2&nah=nops",
88+
"uri":"\/test.pl?id_a=test&nah=nops",
8689
"method":"GET",
8790
"http_version":1.1,
8891
"body":""
@@ -105,15 +108,14 @@
105108
},
106109
"expected":{
107110
"audit_log":"",
108-
"debug_log":"Saving variable: IP:nah with value: nops",
109-
"error_log":""
111+
"debug_log":"Saving variable: IP:id_a with value: nops",
112+
"http_code":403
110113
},
111114
"rules":[
112115
"SecRuleEngine On",
113-
"SecRule ARGS:/^id_/ \"@contains test\" \"id:1,t:lowercase,initcol:ip=%{REMOTE_ADDR},setvar:IP.id_a=test\"",
114-
"SecRule ARGS:/^id_/ \"@contains test\" \"id:3,t:lowercase,setvar:IP.nah=nops\"",
115-
"SecRule IP:/^id_/ \"@contains test\" \"id:2,t:lowercase,initcol:ip=%{REMOTE_ADDR}\"",
116-
"SecRule IP:/^id_/ \"@contains nops\" \"id:4,t:lowercase,block,status:404\""
116+
"SecRule ARGS:/^id_/ \"@contains test\" \"id:11,phase:2,t:lowercase,initcol:ip=%{REMOTE_ADDR}\"",
117+
"SecRule ARGS:/^id_/ \"@contains test\" \"id:12,phase:2,t:lowercase,setvar:IP.id_a=nops\"",
118+
"SecRule IP:/id_a$/ \"@contains nops\" \"id:13,phase:2,deny,status:403\""
117119
]
118120
}
119121
]

0 commit comments

Comments
 (0)