mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Merge pull request #3350 from airween/v3/cppcheckfix
fix: align code to fix cppcheck errors
This commit is contained in:
commit
7a986c7bae
@ -38,7 +38,7 @@ RulesSet *rules = NULL;
|
|||||||
ModSecurity *modsec = NULL;
|
ModSecurity *modsec = NULL;
|
||||||
|
|
||||||
|
|
||||||
void process_special_request (int j) {
|
static void process_special_request (int j) {
|
||||||
Transaction *transaction;
|
Transaction *transaction;
|
||||||
transaction = msc_new_transaction(modsec, rules, NULL);
|
transaction = msc_new_transaction(modsec, rules, NULL);
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ void process_special_request (int j) {
|
|||||||
msc_transaction_cleanup(transaction);
|
msc_transaction_cleanup(transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_request (int j) {
|
static void process_request (int j) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < REQUESTS_PER_PROCESS; i++) {
|
for (i = 0; i < REQUESTS_PER_PROCESS; i++) {
|
||||||
|
@ -53,8 +53,8 @@ class RulesExceptions {
|
|||||||
bool contains(int a);
|
bool contains(int a);
|
||||||
bool merge(RulesExceptions *from);
|
bool merge(RulesExceptions *from);
|
||||||
|
|
||||||
bool loadRemoveRuleByMsg(const std::string &msg, std::string *error);
|
bool loadRemoveRuleByMsg(const std::string &msg, const std::string *error);
|
||||||
bool loadRemoveRuleByTag(const std::string &msg, std::string *error);
|
bool loadRemoveRuleByTag(const std::string &msg, const std::string *error);
|
||||||
|
|
||||||
bool loadUpdateTargetByMsg(const std::string &msg,
|
bool loadUpdateTargetByMsg(const std::string &msg,
|
||||||
std::unique_ptr<std::vector<std::unique_ptr<variables::Variable> > > v,
|
std::unique_ptr<std::vector<std::unique_ptr<variables::Variable> > > v,
|
||||||
|
@ -46,7 +46,7 @@ static inline bool encode(std::string &value) {
|
|||||||
int unicode_len = 0;
|
int unicode_len = 0;
|
||||||
unsigned int d = 0;
|
unsigned int d = 0;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
auto utf = &input[i];
|
const auto* utf = &input[i];
|
||||||
|
|
||||||
c = *utf;
|
c = *utf;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
|
|||||||
std::string digit;
|
std::string digit;
|
||||||
std::string file;
|
std::string file;
|
||||||
std::istream *iss;
|
std::istream *iss;
|
||||||
struct fuzzy_hash_chunk *chunk, *t;
|
std::shared_ptr<fuzzy_hash_chunk> chunk, t;
|
||||||
std::string err;
|
std::string err;
|
||||||
|
|
||||||
auto pos = m_param.find_last_of(' ');
|
auto pos = m_param.find_last_of(' ');
|
||||||
@ -55,11 +55,10 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (std::string line; std::getline(*iss, line); ) {
|
for (std::string line; std::getline(*iss, line); ) {
|
||||||
chunk = (struct fuzzy_hash_chunk *)calloc(1,
|
chunk = std::make_shared<fuzzy_hash_chunk>();
|
||||||
sizeof(struct fuzzy_hash_chunk));
|
|
||||||
|
|
||||||
chunk->data = strdup(line.c_str());
|
chunk->data = std::shared_ptr<char>(strdup(line.c_str()), free);
|
||||||
chunk->next = NULL;
|
chunk->next = nullptr;
|
||||||
|
|
||||||
if (m_head == NULL) {
|
if (m_head == NULL) {
|
||||||
m_head = chunk;
|
m_head = chunk;
|
||||||
@ -83,23 +82,11 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
FuzzyHash::~FuzzyHash() {
|
|
||||||
struct fuzzy_hash_chunk *c = m_head;
|
|
||||||
while (c) {
|
|
||||||
struct fuzzy_hash_chunk *t = c;
|
|
||||||
free(c->data);
|
|
||||||
c->data = NULL;
|
|
||||||
c = c->next;
|
|
||||||
free(t);
|
|
||||||
}
|
|
||||||
m_head = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {
|
bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {
|
||||||
#ifdef WITH_SSDEEP
|
#ifdef WITH_SSDEEP
|
||||||
char result[FUZZY_MAX_RESULT];
|
char result[FUZZY_MAX_RESULT];
|
||||||
struct fuzzy_hash_chunk *chunk = m_head;
|
std::shared_ptr<fuzzy_hash_chunk> chunk = m_head;
|
||||||
|
|
||||||
|
|
||||||
if (fuzzy_hash_buf((const unsigned char*)str.c_str(),
|
if (fuzzy_hash_buf((const unsigned char*)str.c_str(),
|
||||||
str.size(), result)) {
|
str.size(), result)) {
|
||||||
@ -108,7 +95,7 @@ bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (chunk != NULL) {
|
while (chunk != NULL) {
|
||||||
int i = fuzzy_compare(chunk->data, result);
|
int i = fuzzy_compare(chunk->data.get(), result);
|
||||||
if (i >= m_threshold) {
|
if (i >= m_threshold) {
|
||||||
ms_dbg_a(t, 4, "Fuzzy hash: matched " \
|
ms_dbg_a(t, 4, "Fuzzy hash: matched " \
|
||||||
"with score: " + std::to_string(i) + ".");
|
"with score: " + std::to_string(i) + ".");
|
||||||
|
@ -31,8 +31,8 @@ namespace operators {
|
|||||||
|
|
||||||
|
|
||||||
struct fuzzy_hash_chunk {
|
struct fuzzy_hash_chunk {
|
||||||
char *data;
|
std::shared_ptr<char> data;
|
||||||
struct fuzzy_hash_chunk *next;
|
std::shared_ptr<fuzzy_hash_chunk> next;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FuzzyHash : public Operator {
|
class FuzzyHash : public Operator {
|
||||||
@ -42,14 +42,14 @@ class FuzzyHash : public Operator {
|
|||||||
: Operator("FuzzyHash", std::move(param)),
|
: Operator("FuzzyHash", std::move(param)),
|
||||||
m_threshold(0),
|
m_threshold(0),
|
||||||
m_head(NULL) { }
|
m_head(NULL) { }
|
||||||
~FuzzyHash() override;
|
~FuzzyHash() override = default;
|
||||||
|
|
||||||
bool evaluate(Transaction *transaction, const std::string &std) override;
|
bool evaluate(Transaction *transaction, const std::string &std) override;
|
||||||
|
|
||||||
bool init(const std::string ¶m, std::string *error) override;
|
bool init(const std::string ¶m, std::string *error) override;
|
||||||
private:
|
private:
|
||||||
int m_threshold;
|
int m_threshold;
|
||||||
struct fuzzy_hash_chunk *m_head;
|
std::shared_ptr<fuzzy_hash_chunk> m_head;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace operators
|
} // namespace operators
|
||||||
|
@ -1638,7 +1638,7 @@ bool Multipart::process(const std::string& data, std::string *error,
|
|||||||
}
|
}
|
||||||
} else { /* It looks like a boundary but */
|
} else { /* It looks like a boundary but */
|
||||||
/* we couldn't match it. */
|
/* we couldn't match it. */
|
||||||
char *p = NULL;
|
const char *p = NULL;
|
||||||
|
|
||||||
/* Check if an attempt to use quotes around the
|
/* Check if an attempt to use quotes around the
|
||||||
* boundary was made. */
|
* boundary was made. */
|
||||||
|
@ -58,7 +58,7 @@ bool RulesExceptions::loadUpdateActionById(double id,
|
|||||||
|
|
||||||
|
|
||||||
bool RulesExceptions::loadRemoveRuleByMsg(const std::string &msg,
|
bool RulesExceptions::loadRemoveRuleByMsg(const std::string &msg,
|
||||||
std::string *error) {
|
const std::string *error) {
|
||||||
m_remove_rule_by_msg.push_back(msg);
|
m_remove_rule_by_msg.push_back(msg);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -66,7 +66,7 @@ bool RulesExceptions::loadRemoveRuleByMsg(const std::string &msg,
|
|||||||
|
|
||||||
|
|
||||||
bool RulesExceptions::loadRemoveRuleByTag(const std::string &msg,
|
bool RulesExceptions::loadRemoveRuleByTag(const std::string &msg,
|
||||||
std::string *error) {
|
const std::string *error) {
|
||||||
m_remove_rule_by_tag.push_back(msg);
|
m_remove_rule_by_tag.push_back(msg);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user