Adds support to the transformation normalisePath and normalisePathWin

This commit is contained in:
Felipe Zimmerle 2015-10-23 11:23:53 -03:00
parent 7ab75ac015
commit 7e826633f1
4 changed files with 27 additions and 15 deletions

View File

@ -15,6 +15,8 @@
#include "actions/transformations/normalise_path.h"
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
@ -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

View File

@ -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;

View File

@ -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); }

@ -1 +1 @@
Subproject commit 76c4bd6460a870b481eb4d36fcead7818b20d7d9
Subproject commit 26af965147db5aae11c56bebea9649f4ea7cb1d4