diff --git a/src/actions/transformations/remove_nulls.cc b/src/actions/transformations/remove_nulls.cc index 68996aad..01c2d94c 100644 --- a/src/actions/transformations/remove_nulls.cc +++ b/src/actions/transformations/remove_nulls.cc @@ -26,7 +26,7 @@ #include "modsecurity/assay.h" #include "actions/transformations/transformation.h" - +#include "src/utils.h" namespace ModSecurity { namespace actions { @@ -37,17 +37,16 @@ std::string RemoveNulls::evaluate(std::string value, Assay *assay) { int64_t i; - std::string ret; - i = 0; while (i < value.size()) { - if (value.at(i) != '\0') { - ret += value.at(i); + if (value.at(i) == '\0') { + value.erase(i, 1); + } else { + i++; } - i++; } - return ret; + return value; } diff --git a/test/unit/unit_test.cc b/test/unit/unit_test.cc index 341abafc..dcdc4e4e 100644 --- a/test/unit/unit_test.cc +++ b/test/unit/unit_test.cc @@ -93,7 +93,7 @@ UnitTest *UnitTest::from_yajl_node(yajl_val &node) { u->param = YAJL_GET_STRING(val); } else if (strcmp(key, "input") == 0) { u->input = YAJL_GET_STRING(val); - replaceAll(&(u->input), "\\0", '\u0000'); + replaceAll(&(u->input), "\\0", '\0'); replaceAll(&(u->input), "\\xe4", '\xe4'); replaceAll(&(u->input), "\\x03", '\x03'); replaceAll(&(u->input), "\\xbf", '\xbf'); @@ -110,6 +110,7 @@ UnitTest *UnitTest::from_yajl_node(yajl_val &node) { } else if (strcmp(key, "output") == 0) { u->output = YAJL_GET_STRING(val); replaceAll(&(u->output), "\\u0000", '\u0000'); + replaceAll(&(u->output), "\\0", '\u0000'); } }