Fix crash on SecRuleRemoveById malformated parameter

Fix issue #1440
This commit is contained in:
Felipe Zimmerle
2017-06-06 22:11:09 -03:00
parent 2a5085255e
commit e795253ecf
6 changed files with 2118 additions and 2130 deletions

View File

@@ -47,6 +47,24 @@ namespace utils {
namespace string {
std::string parserSanitizer(std::string a) {
a = removeWhiteSpacesIfNeeded(a);
a = removeBracketsIfNeeded(a);
return a;
}
std::string removeWhiteSpacesIfNeeded(std::string a) {
while (a.size() > 1 && a.at(0) == ' ') {
a.erase(0, 1);
}
while (a.size() > 1 && a.at(a.length()-1) == ' ') {
a.pop_back();
}
return a;
}
std::string ascTime(time_t *t) {
std::string ts = std::ctime(t);
ts.pop_back();
@@ -87,7 +105,7 @@ std::string limitTo(int amount, const std::string &str) {
std::string removeBracketsIfNeeded(std::string a) {
if ((a.at(0) == '"') && (a.at(a.length()-1) == '"')) {
if (a.length() > 1 && a.at(0) == '"' && a.at(a.length()-1) == '"') {
a.pop_back();
a.erase(0, 1);
}

View File

@@ -68,6 +68,8 @@ std::vector<std::string> split(std::string str, char delimiter);
void chomp(std::string *str);
void replaceAll(std::string *str, const std::string& from,
const std::string& to);
std::string removeWhiteSpacesIfNeeded(std::string a);
std::string parserSanitizer(std::string a);
unsigned char x2c(unsigned char *what);
unsigned char xsingle2c(unsigned char *what);