From 7e826633f1857ddf00a7115f9c859c1365751ebf Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 23 Oct 2015 11:23:53 -0300 Subject: [PATCH] Adds support to the transformation normalisePath and normalisePathWin --- src/actions/transformations/normalise_path.cc | 27 ++++++++++++------- .../transformations/normalise_path_win.cc | 11 +++++--- src/actions/transformations/transformation.cc | 2 +- test/test-cases/secrules-language-tests | 2 +- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/actions/transformations/normalise_path.cc b/src/actions/transformations/normalise_path.cc index 926ebb5a..7f482bbb 100644 --- a/src/actions/transformations/normalise_path.cc +++ b/src/actions/transformations/normalise_path.cc @@ -15,6 +15,8 @@ #include "actions/transformations/normalise_path.h" +#include + #include #include #include @@ -24,6 +26,7 @@ #include "modsecurity/assay.h" #include "actions/transformations/transformation.h" +#include "src/utils.h" namespace ModSecurity { @@ -37,16 +40,20 @@ NormalisePath::NormalisePath(std::string action) std::string NormalisePath::evaluate(std::string value, Assay *assay) { - /** - * @todo Implement the transformation NormalisePath - */ - if (assay) { -#ifndef NO_LOGS - assay->debug(4, "Transformation NormalisePath is not" \ - " implemented yet."); -#endif - } - return value; + int changed = 0; + + char *tmp = (char *) malloc(sizeof(char) * value.size() + 1); + memcpy(tmp, value.c_str(), value.size() + 1); + tmp[value.size()] = '\0'; + + int i = normalize_path_inplace((unsigned char *)tmp, + value.size(), 0, &changed); + + std::string ret(""); + ret.assign(tmp, i); + free(tmp); + + return ret; } } // namespace transformations diff --git a/src/actions/transformations/normalise_path_win.cc b/src/actions/transformations/normalise_path_win.cc index d9e135ac..69cd1f63 100644 --- a/src/actions/transformations/normalise_path_win.cc +++ b/src/actions/transformations/normalise_path_win.cc @@ -37,11 +37,16 @@ namespace transformations { std::string NormalisePathWin::evaluate(std::string value, Assay *assay) { int changed; - char *tmp = strdup(value.c_str()); - normalize_path_inplace((unsigned char *)tmp, + + char *tmp = (char *) malloc(sizeof(char) * value.size() + 1); + memcpy(tmp, value.c_str(), value.size() + 1); + tmp[value.size()] = '\0'; + + int i = normalize_path_inplace((unsigned char *)tmp, value.size(), 1, &changed); + std::string ret(""); - ret.assign(tmp); + ret.assign(tmp, i); free(tmp); return ret; diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index fc0829f3..c5a32267 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -88,8 +88,8 @@ Transformation* Transformation::instantiate(std::string a) { IF_MATCH(lowercase) { return new LowerCase(a); } IF_MATCH(md5) { return new Md5(a); } IF_MATCH(none) { return new None(a); } - IF_MATCH(normalise_path) { return new NormalisePath(a); } IF_MATCH(normalisePathWin) { return new NormalisePathWin(a); } + IF_MATCH(normalisePath) { return new NormalisePath(a); } IF_MATCH(parity_even_7bit) { return new ParityEven7bit(a); } IF_MATCH(parity_odd_7bit) { return new ParityOdd7bit(a); } IF_MATCH(parity_zero_7bit) { return new ParityZero7bit(a); } diff --git a/test/test-cases/secrules-language-tests b/test/test-cases/secrules-language-tests index 76c4bd64..26af9651 160000 --- a/test/test-cases/secrules-language-tests +++ b/test/test-cases/secrules-language-tests @@ -1 +1 @@ -Subproject commit 76c4bd6460a870b481eb4d36fcead7818b20d7d9 +Subproject commit 26af965147db5aae11c56bebea9649f4ea7cb1d4