mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Adds support to replaceComments transformation
This commit is contained in:
parent
7e826633f1
commit
0ae09201f5
@ -24,6 +24,7 @@
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
#include "actions/transformations/transformation.h"
|
||||
#include "src/utils.h"
|
||||
|
||||
|
||||
namespace ModSecurity {
|
||||
@ -37,16 +38,51 @@ ReplaceComments::ReplaceComments(std::string action)
|
||||
|
||||
std::string ReplaceComments::evaluate(std::string value,
|
||||
Assay *assay) {
|
||||
/**
|
||||
* @todo Implement the transformation ReplaceComments
|
||||
*/
|
||||
if (assay) {
|
||||
#ifndef NO_LOGS
|
||||
assay->debug(4, "Transformation ReplaceComments " \
|
||||
"is not implemented yet.");
|
||||
#endif
|
||||
|
||||
long int i, j, incomment;
|
||||
int changed = 0;
|
||||
|
||||
char *input = (char *) malloc(sizeof(char) * value.size() + 1);
|
||||
memcpy(input, value.c_str(), value.size() + 1);
|
||||
input[value.size()] = '\0';
|
||||
|
||||
i = j = incomment = 0;
|
||||
while(i < value.size()) {
|
||||
if (incomment == 0) {
|
||||
if ((input[i] == '/') && (i + 1 < value.size())
|
||||
&& (input[i + 1] == '*')) {
|
||||
changed = 1;
|
||||
incomment = 1;
|
||||
i += 2;
|
||||
} else {
|
||||
input[j] = input[i];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
} else {
|
||||
if ((input[i] == '*') && (i + 1 < value.size())
|
||||
&& (input[i + 1] == '/')) {
|
||||
incomment = 0;
|
||||
i += 2;
|
||||
input[j] = ' ';
|
||||
j++;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
|
||||
if (incomment) {
|
||||
input[j++] = ' ';
|
||||
}
|
||||
|
||||
|
||||
std::string resp;
|
||||
resp.append((char *)input, j);
|
||||
|
||||
free(input);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
} // namespace transformations
|
||||
|
@ -98,7 +98,7 @@ Transformation* Transformation::instantiate(std::string a) {
|
||||
IF_MATCH(removeNulls) { return new RemoveNulls(a); }
|
||||
IF_MATCH(remove_whitespace) { return new RemoveWhitespace(a); }
|
||||
IF_MATCH(compressWhitespace) { return new CompressWhitespace(a); }
|
||||
IF_MATCH(replace_comments) { return new ReplaceComments(a); }
|
||||
IF_MATCH(replaceComments) { return new ReplaceComments(a); }
|
||||
IF_MATCH(replace_nulls) { return new ReplaceNulls(a); }
|
||||
IF_MATCH(sha1) { return new Sha1(a); }
|
||||
IF_MATCH(sql_hex_decode) { return new SqlHexDecode(a); }
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 26af965147db5aae11c56bebea9649f4ea7cb1d4
|
||||
Subproject commit 444dfbea3390cf54f6d59e331bc4fbcabb77eb4e
|
Loading…
x
Reference in New Issue
Block a user