mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Perform CmdLine transformation in-place
This commit is contained in:
parent
3ff72fbbc5
commit
13203ae5e7
@ -20,10 +20,10 @@ namespace modsecurity::actions::transformations {
|
||||
|
||||
|
||||
bool CmdLine::transform(std::string &value, const Transaction *trans) const {
|
||||
std::string ret;
|
||||
int space = 0;
|
||||
char *d = value.data();
|
||||
bool space = false;
|
||||
|
||||
for (auto& a : value) {
|
||||
for (const auto& a : value) {
|
||||
switch (a) {
|
||||
/* remove some characters */
|
||||
case '"':
|
||||
@ -39,9 +39,9 @@ bool CmdLine::transform(std::string &value, const Transaction *trans) const {
|
||||
case '\t':
|
||||
case '\r':
|
||||
case '\n':
|
||||
if (space == 0) {
|
||||
ret.append(" ");
|
||||
space++;
|
||||
if (space == false) {
|
||||
*d++ = ' ';
|
||||
space = true;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -49,23 +49,24 @@ bool CmdLine::transform(std::string &value, const Transaction *trans) const {
|
||||
case '/':
|
||||
case '(':
|
||||
if (space) {
|
||||
ret.pop_back();
|
||||
d--;
|
||||
}
|
||||
space = 0;
|
||||
ret.append(&a, 1);
|
||||
space = false;
|
||||
*d++ = a;
|
||||
break;
|
||||
|
||||
/* copy normal characters */
|
||||
default :
|
||||
char b = std::tolower(a);
|
||||
ret.append(&b, 1);
|
||||
space = 0;
|
||||
*d++ = b;
|
||||
space = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const auto changed = ret != value;
|
||||
value = ret;
|
||||
const auto new_len = d - value.c_str();
|
||||
const auto changed = new_len != value.length();
|
||||
value.resize(new_len);
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user