Skip to content

Commit f1f2527

Browse files
committed
Using setenv instead of putenv on SetEnv action
1 parent 03b3e47 commit f1f2527

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
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+
- Replaces put with setenv in SetEnv action
5+
[Issue #2469 - @martinhsv, @WGH-, @zimmerle]
46
- Regression: Mark the test as failed in case of segfault.
57
[@zimmerle]
68
- Regex key selection should not be case-sensitive

src/actions/set_env.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ bool SetENV::init(std::string *error) {
3434
bool SetENV::evaluate(RuleWithActions *rule, Transaction *t) {
3535
std::string colNameExpanded(m_string->evaluate(t));
3636

37+
auto pair = utils::string::ssplit_pair(colNameExpanded, '=');
3738
ms_dbg_a(t, 8, "Setting envoriment variable: "
38-
+ colNameExpanded + ".");
39-
40-
putenv(strdup(colNameExpanded.c_str()));
39+
+ pair.first + " to " + pair.second);
40+
setenv(pair.first.c_str(), pair.second.c_str(), /*overwrite*/ 1);
4141

4242
return true;
4343
}

test/test-cases/regression/action-setenv.json

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
{
33
"enabled":1,
44
"version_min":300000,
5-
"title":"Testing setsid action (1/2)",
5+
"title":"Testing setsid action (1/3)",
66
"expected":{
7-
"debug_log": "Setting envoriment variable: variable=PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120"
7+
"debug_log": "Setting envoriment variable: variable to PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120"
88
},
99
"client":{
1010
"ip":"200.249.12.31",
@@ -33,9 +33,9 @@
3333
{
3434
"enabled":1,
3535
"version_min":300000,
36-
"title":"Testing setenv action (2/2)",
36+
"title":"Testing setenv action (2/3)",
3737
"expected":{
38-
"debug_log": "Setting envoriment variable: variable=PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120"
38+
"debug_log": "Setting envoriment variable: variable to PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120"
3939
},
4040
"client":{
4141
"ip":"200.249.12.31",
@@ -60,5 +60,36 @@
6060
"SecRuleEngine On",
6161
"SecRule REQUEST_HEADERS:Cookie \"^(.*)$\" \"id:'900018',phase:2,setenv:variable=%{matched_var},pass\""
6262
]
63+
},
64+
{
65+
"enabled":1,
66+
"version_min":300000,
67+
"title":"Testing setenv action (3/3)",
68+
"expected":{
69+
"debug_log": "Setting envoriment variable: variable to PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120==test=test"
70+
},
71+
"client":{
72+
"ip":"200.249.12.31",
73+
"port":123
74+
},
75+
"request":{
76+
"headers":{
77+
"Host":"localhost",
78+
"User-Agent":"curl/7.38.0",
79+
"Accept":"*/*",
80+
"User-Agent":"My sweet little browser",
81+
"Cookie": "PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120"
82+
},
83+
"uri":"/?key=value&key=other_value",
84+
"method":"GET"
85+
},
86+
"server":{
87+
"ip":"200.249.12.31",
88+
"port":80
89+
},
90+
"rules":[
91+
"SecRuleEngine On",
92+
"SecRule REQUEST_HEADERS:Cookie \"^(.*)$\" \"id:'900018',phase:2,setenv:variable=%{matched_var}==test=test,pass\""
93+
]
6394
}
6495
]

0 commit comments

Comments
 (0)