Code cosmetics

This commit is contained in:
Felipe Zimmerle 2015-11-18 12:59:08 -03:00
parent 3c45a57130
commit de79848285
11 changed files with 37 additions and 32 deletions

View File

@ -24,13 +24,15 @@ typedef struct Collection_t Collection;
#ifdef __cplusplus #ifdef __cplusplus
#include <string>
namespace ModSecurity { namespace ModSecurity {
class Collection : public transaction::Variables { class Collection : public transaction::Variables {
public: public:
Collection(std::string name, std::string key) Collection(std::string name, std::string key)
: m_name(name), : m_name(name),
m_key(key) { }; m_key(key) { }
std::string m_name; std::string m_name;
clock_t m_createTime; clock_t m_createTime;

View File

@ -61,7 +61,6 @@ class Variables :
std::vector<const transaction::Variable *> *l); std::vector<const transaction::Variable *> *l);
void resolveRegularExpression(const std::string& var, void resolveRegularExpression(const std::string& var,
std::vector<const transaction::Variable *> *l); std::vector<const transaction::Variable *> *l);
}; };
} // namespace transaction } // namespace transaction

View File

@ -30,7 +30,8 @@ namespace actions {
namespace transformations { namespace transformations {
class HtmlEntityDecodeInstantCache : public std::unordered_map<std::string, std::string> { class HtmlEntityDecodeInstantCache :
public std::unordered_map<std::string, std::string> {
public: public:
static HtmlEntityDecodeInstantCache& getInstance() { static HtmlEntityDecodeInstantCache& getInstance() {
static HtmlEntityDecodeInstantCache instance; static HtmlEntityDecodeInstantCache instance;
@ -44,7 +45,7 @@ class HtmlEntityDecodeInstantCache : public std::unordered_map<std::string, std:
} }
} }
private: private:
HtmlEntityDecodeInstantCache() {}; HtmlEntityDecodeInstantCache() {}
}; };

View File

@ -29,7 +29,8 @@ class Assay;
namespace actions { namespace actions {
namespace transformations { namespace transformations {
class LowerCaseInstantCache : public std::unordered_map<std::string, std::string> { class LowerCaseInstantCache :
public std::unordered_map<std::string, std::string> {
public: public:
static LowerCaseInstantCache& getInstance() { static LowerCaseInstantCache& getInstance() {
static LowerCaseInstantCache instance; static LowerCaseInstantCache instance;
@ -43,7 +44,7 @@ class LowerCaseInstantCache : public std::unordered_map<std::string, std::string
} }
} }
private: private:
LowerCaseInstantCache() {}; LowerCaseInstantCache() {}
}; };

View File

@ -29,7 +29,8 @@ class Assay;
namespace actions { namespace actions {
namespace transformations { namespace transformations {
class UrlDecodeInstantCache : public std::unordered_map<std::string, std::string> { class UrlDecodeInstantCache :
public std::unordered_map<std::string, std::string> {
public: public:
static UrlDecodeInstantCache& getInstance() { static UrlDecodeInstantCache& getInstance() {
static UrlDecodeInstantCache instance; static UrlDecodeInstantCache instance;
@ -43,7 +44,7 @@ class UrlDecodeInstantCache : public std::unordered_map<std::string, std::string
} }
} }
private: private:
UrlDecodeInstantCache() {}; UrlDecodeInstantCache() {}
}; };

View File

@ -132,9 +132,7 @@ void Collections::resolveSingleMatch(const std::string& var,
try { try {
this->at(collection)->resolveSingleMatch(var, l); this->at(collection)->resolveSingleMatch(var, l);
} catch (...) { } catch (...) { }
}
} }
void Collections::resolveMultiMatches(const std::string& var, void Collections::resolveMultiMatches(const std::string& var,
@ -149,9 +147,7 @@ void Collections::resolveMultiMatches(const std::string& var,
std::vector<const transaction::Variable *> *l) { std::vector<const transaction::Variable *> *l) {
try { try {
this->at(collection)->resolveMultiMatches(var, l); this->at(collection)->resolveMultiMatches(var, l);
} catch (...) { } catch (...) { }
}
} }
void Collections::resolveRegularExpression(const std::string& var, void Collections::resolveRegularExpression(const std::string& var,
@ -166,9 +162,7 @@ void Collections::resolveRegularExpression(const std::string& var,
try { try {
this->at(collection)->resolveRegularExpression(var, l); this->at(collection)->resolveRegularExpression(var, l);
} catch (...) { } catch (...) { }
}
} }
} // namespace transaction } // namespace transaction

View File

@ -17,6 +17,7 @@
#define SRC_OPERATORS_DETECT_SQLI_H_ #define SRC_OPERATORS_DETECT_SQLI_H_
#include <string> #include <string>
#include <list>
#include "operators/operator.h" #include "operators/operator.h"

View File

@ -488,7 +488,6 @@ bool Rule::evaluate(Assay *assay) {
delete e.back(); delete e.back();
e.pop_back(); e.pop_back();
} }
//delete e;
} }
return ret; return ret;
} }

View File

@ -96,8 +96,7 @@ void Variables::resolveMultiMatches(const std::string& var,
if (x.first.compare(0, keySize, var) != 0) { if (x.first.compare(0, keySize, var) != 0) {
continue; continue;
} }
const transaction::Variable *v = new transaction::Variable(x.first, x.second); l->insert(l->begin(), new transaction::Variable(x.first, x.second));
l->insert(l->begin(), v);
} }
} }

View File

@ -34,7 +34,6 @@ Variable::Variable(std::string name)
m_collectionName(""), m_collectionName(""),
m_isExclusion(false), m_isExclusion(false),
m_isCount(false) { m_isCount(false) {
if (m_name.at(0) == '\\') { if (m_name.at(0) == '\\') {
m_type = RegularExpression; m_type = RegularExpression;
} else if (m_name.find(":") != std::string::npos) { } else if (m_name.find(":") != std::string::npos) {
@ -58,7 +57,6 @@ Variable::Variable(std::string name, VariableKind kind)
m_kind(kind), m_kind(kind),
m_isExclusion(false), m_isExclusion(false),
m_isCount(false) { m_isCount(false) {
if (m_name.at(0) == '\\') { if (m_name.at(0) == '\\') {
m_type = RegularExpression; m_type = RegularExpression;
} else if (m_name.find(":") != std::string::npos) { } else if (m_name.find(":") != std::string::npos) {
@ -75,25 +73,32 @@ Variable::Variable(std::string name, VariableKind kind)
std::vector<const transaction::Variable *> * std::vector<const transaction::Variable *> *
Variable::evaluate(Assay *assay) { Variable::evaluate(Assay *assay) {
std::vector<const transaction::Variable *> *l = new std::vector<const transaction::Variable *>(); std::vector<const transaction::Variable *> *l = NULL;
l = new std::vector<const transaction::Variable *>();
evaluate(assay, l); evaluate(assay, l);
return l; return l;
} }
void Variable::evaluateInternal(Assay *assay, std::vector<const transaction::Variable *> *l) { void Variable::evaluateInternal(Assay *assay,
std::vector<const transaction::Variable *> *l) {
if (m_collectionName.empty() == false) { if (m_collectionName.empty() == false) {
if (m_kind == CollectionVarible && m_type == MultipleMatches) { if (m_kind == CollectionVarible && m_type == MultipleMatches) {
assay->m_collections.resolveMultiMatches(m_name, m_collectionName, l); assay->m_collections.resolveMultiMatches(m_name,
} if (m_kind == CollectionVarible && m_type == RegularExpression) { m_collectionName, l);
assay->m_collections.resolveRegularExpression(m_name, m_collectionName, l); } else if (m_kind == CollectionVarible
&& m_type == RegularExpression) {
assay->m_collections.resolveRegularExpression(m_name,
m_collectionName, l);
} else { } else {
assay->m_collections.resolveSingleMatch(m_name, m_collectionName, l); assay->m_collections.resolveSingleMatch(m_name,
m_collectionName, l);
} }
} else { } else {
if (m_kind == CollectionVarible && m_type == MultipleMatches) { if (m_kind == CollectionVarible && m_type == MultipleMatches) {
assay->m_collections.resolveMultiMatches(m_name, l); assay->m_collections.resolveMultiMatches(m_name, l);
} if (m_kind == CollectionVarible && m_type == RegularExpression) { } else if (m_kind == CollectionVarible
&& m_type == RegularExpression) {
assay->m_collections.resolveRegularExpression(m_name, l); assay->m_collections.resolveRegularExpression(m_name, l);
} else { } else {
assay->m_collections.resolveSingleMatch(m_name, l); assay->m_collections.resolveSingleMatch(m_name, l);
@ -102,7 +107,8 @@ void Variable::evaluateInternal(Assay *assay, std::vector<const transaction::Var
} }
void Variable::evaluate(Assay *assay, std::vector<const transaction::Variable *> *l) { void Variable::evaluate(Assay *assay,
std::vector<const transaction::Variable *> *l) {
evaluateInternal(assay, l); evaluateInternal(assay, l);
} }

View File

@ -67,8 +67,10 @@ class Variable {
static std::string to_s(std::vector<Variable *> *variables); static std::string to_s(std::vector<Variable *> *variables);
virtual std::vector<const transaction::Variable *> *evaluate(Assay *assay); virtual std::vector<const transaction::Variable *> *evaluate(Assay *assay);
virtual void evaluate(Assay *assay, std::vector<const transaction::Variable *> *l); virtual void evaluate(Assay *assay,
virtual void evaluateInternal(Assay *assay, std::vector<const transaction::Variable *> *l); std::vector<const transaction::Variable *> *l);
virtual void evaluateInternal(Assay *assay,
std::vector<const transaction::Variable *> *l);
std::string m_name; std::string m_name;