Adds support to replaceComments transformation

This commit is contained in:
Felipe Zimmerle 2015-10-23 13:05:08 -03:00
parent 7e826633f1
commit 0ae09201f5
3 changed files with 47 additions and 11 deletions

View File

@ -24,6 +24,7 @@
#include "modsecurity/assay.h" #include "modsecurity/assay.h"
#include "actions/transformations/transformation.h" #include "actions/transformations/transformation.h"
#include "src/utils.h"
namespace ModSecurity { namespace ModSecurity {
@ -37,16 +38,51 @@ ReplaceComments::ReplaceComments(std::string action)
std::string ReplaceComments::evaluate(std::string value, std::string ReplaceComments::evaluate(std::string value,
Assay *assay) { Assay *assay) {
/**
* @todo Implement the transformation ReplaceComments long int i, j, incomment;
*/ int changed = 0;
if (assay) {
#ifndef NO_LOGS char *input = (char *) malloc(sizeof(char) * value.size() + 1);
assay->debug(4, "Transformation ReplaceComments " \ memcpy(input, value.c_str(), value.size() + 1);
"is not implemented yet."); input[value.size()] = '\0';
#endif
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++;
} }
return value; } else {
if ((input[i] == '*') && (i + 1 < value.size())
&& (input[i + 1] == '/')) {
incomment = 0;
i += 2;
input[j] = ' ';
j++;
} else {
i++;
}
}
}
if (incomment) {
input[j++] = ' ';
}
std::string resp;
resp.append((char *)input, j);
free(input);
return resp;
} }
} // namespace transformations } // namespace transformations

View File

@ -98,7 +98,7 @@ Transformation* Transformation::instantiate(std::string a) {
IF_MATCH(removeNulls) { return new RemoveNulls(a); } IF_MATCH(removeNulls) { return new RemoveNulls(a); }
IF_MATCH(remove_whitespace) { return new RemoveWhitespace(a); } IF_MATCH(remove_whitespace) { return new RemoveWhitespace(a); }
IF_MATCH(compressWhitespace) { return new CompressWhitespace(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(replace_nulls) { return new ReplaceNulls(a); }
IF_MATCH(sha1) { return new Sha1(a); } IF_MATCH(sha1) { return new Sha1(a); }
IF_MATCH(sql_hex_decode) { return new SqlHexDecode(a); } IF_MATCH(sql_hex_decode) { return new SqlHexDecode(a); }

@ -1 +1 @@
Subproject commit 26af965147db5aae11c56bebea9649f4ea7cb1d4 Subproject commit 444dfbea3390cf54f6d59e331bc4fbcabb77eb4e