mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-19 18:54:23 +03:00
Adds RemoveNulls trasnformation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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); }
|
||||
|
||||
Reference in New Issue
Block a user