Adds RemoveNulls trasnformation

This commit is contained in:
Felipe Zimmerle
2015-08-05 22:03:26 -03:00
parent 62d004cf04
commit 6dad6af4a9
7 changed files with 74 additions and 12 deletions

View File

@@ -15,6 +15,8 @@
#include "actions/transformations/remove_nulls.h"
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
@@ -30,20 +32,31 @@ namespace ModSecurity {
namespace actions {
namespace transformations {
RemoveNulls::RemoveNulls(std::string action)
: Transformation(action) {
this->action_kind = 1;
}
std::string RemoveNulls::evaluate(std::string value,
Assay *assay) {
/**
* @todo Implement the transformation RemoveNulls
*/
assay->debug(4, "Transformation RemoveNulls is not implemented yet.");
return value;
int64_t i, j;
char *input = reinterpret_cast<char *>(malloc(value.size()
* sizeof(char)));
memcpy(input, value.c_str(), value.size());
i = j = 0;
while (i < value.size()) {
if (input[i] != '\0') {
input[j] = input[i];
j++;
}
i++;
}
std::string ret(input, 0, j);
free(input);
return ret;
}
} // namespace transformations
} // namespace actions
} // namespace ModSecurity

View File

@@ -30,7 +30,9 @@ namespace transformations {
class RemoveNulls : public Transformation {
public:
explicit RemoveNulls(std::string action);
explicit RemoveNulls(std::string action)
: Transformation(action) { }
std::string evaluate(std::string exp,
Assay *assay) override;
};

View File

@@ -94,7 +94,7 @@ Transformation* Transformation::instantiate(std::string a) {
IF_MATCH(parity_zero_7bit) { return new ParityZero7bit(a); }
IF_MATCH(remove_comments_char) { return new RemoveCommentsChar(a); }
IF_MATCH(remove_comments) { return new RemoveComments(a); }
IF_MATCH(remove_nulls) { return new RemoveNulls(a); }
IF_MATCH(removeNulls) { return new RemoveNulls(a); }
IF_MATCH(remove_whitespace) { return new RemoveWhitespace(a); }
IF_MATCH(replace_comments) { return new ReplaceComments(a); }
IF_MATCH(replace_nulls) { return new ReplaceNulls(a); }