Skip to content

Commit 7a986c7

Browse files
authored
Merge pull request #3350 from airween/v3/cppcheckfix
fix: align code to fix cppcheck errors
2 parents 1a2b139 + 8f00f47 commit 7a986c7

File tree

7 files changed

+19
-32
lines changed

7 files changed

+19
-32
lines changed

Diff for: examples/multiprocess_c/multi.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RulesSet *rules = NULL;
3838
ModSecurity *modsec = NULL;
3939

4040

41-
void process_special_request (int j) {
41+
static void process_special_request (int j) {
4242
Transaction *transaction;
4343
transaction = msc_new_transaction(modsec, rules, NULL);
4444

@@ -60,7 +60,7 @@ void process_special_request (int j) {
6060
msc_transaction_cleanup(transaction);
6161
}
6262

63-
void process_request (int j) {
63+
static void process_request (int j) {
6464
int i;
6565

6666
for (i = 0; i < REQUESTS_PER_PROCESS; i++) {

Diff for: headers/modsecurity/rules_exceptions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class RulesExceptions {
5353
bool contains(int a);
5454
bool merge(RulesExceptions *from);
5555

56-
bool loadRemoveRuleByMsg(const std::string &msg, std::string *error);
57-
bool loadRemoveRuleByTag(const std::string &msg, std::string *error);
56+
bool loadRemoveRuleByMsg(const std::string &msg, const std::string *error);
57+
bool loadRemoveRuleByTag(const std::string &msg, const std::string *error);
5858

5959
bool loadUpdateTargetByMsg(const std::string &msg,
6060
std::unique_ptr<std::vector<std::unique_ptr<variables::Variable> > > v,

Diff for: src/actions/transformations/utf8_to_unicode.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static inline bool encode(std::string &value) {
4646
int unicode_len = 0;
4747
unsigned int d = 0;
4848
unsigned char c;
49-
auto utf = &input[i];
49+
const auto* utf = &input[i];
5050

5151
c = *utf;
5252

Diff for: src/operators/fuzzy_hash.cc

+7-20
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool FuzzyHash::init(const std::string &param2, std::string *error) {
2828
std::string digit;
2929
std::string file;
3030
std::istream *iss;
31-
struct fuzzy_hash_chunk *chunk, *t;
31+
std::shared_ptr<fuzzy_hash_chunk> chunk, t;
3232
std::string err;
3333

3434
auto pos = m_param.find_last_of(' ');
@@ -55,11 +55,10 @@ bool FuzzyHash::init(const std::string &param2, std::string *error) {
5555
}
5656

5757
for (std::string line; std::getline(*iss, line); ) {
58-
chunk = (struct fuzzy_hash_chunk *)calloc(1,
59-
sizeof(struct fuzzy_hash_chunk));
58+
chunk = std::make_shared<fuzzy_hash_chunk>();
6059

61-
chunk->data = strdup(line.c_str());
62-
chunk->next = NULL;
60+
chunk->data = std::shared_ptr<char>(strdup(line.c_str()), free);
61+
chunk->next = nullptr;
6362

6463
if (m_head == NULL) {
6564
m_head = chunk;
@@ -83,23 +82,11 @@ bool FuzzyHash::init(const std::string &param2, std::string *error) {
8382
#endif
8483
}
8584

86-
FuzzyHash::~FuzzyHash() {
87-
struct fuzzy_hash_chunk *c = m_head;
88-
while (c) {
89-
struct fuzzy_hash_chunk *t = c;
90-
free(c->data);
91-
c->data = NULL;
92-
c = c->next;
93-
free(t);
94-
}
95-
m_head = NULL;
96-
}
97-
98-
9985
bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {
10086
#ifdef WITH_SSDEEP
10187
char result[FUZZY_MAX_RESULT];
102-
struct fuzzy_hash_chunk *chunk = m_head;
88+
std::shared_ptr<fuzzy_hash_chunk> chunk = m_head;
89+
10390

10491
if (fuzzy_hash_buf((const unsigned char*)str.c_str(),
10592
str.size(), result)) {
@@ -108,7 +95,7 @@ bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {
10895
}
10996

11097
while (chunk != NULL) {
111-
int i = fuzzy_compare(chunk->data, result);
98+
int i = fuzzy_compare(chunk->data.get(), result);
11299
if (i >= m_threshold) {
113100
ms_dbg_a(t, 4, "Fuzzy hash: matched " \
114101
"with score: " + std::to_string(i) + ".");

Diff for: src/operators/fuzzy_hash.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace operators {
3131

3232

3333
struct fuzzy_hash_chunk {
34-
char *data;
35-
struct fuzzy_hash_chunk *next;
34+
std::shared_ptr<char> data;
35+
std::shared_ptr<fuzzy_hash_chunk> next;
3636
};
3737

3838
class FuzzyHash : public Operator {
@@ -42,14 +42,14 @@ class FuzzyHash : public Operator {
4242
: Operator("FuzzyHash", std::move(param)),
4343
m_threshold(0),
4444
m_head(NULL) { }
45-
~FuzzyHash() override;
45+
~FuzzyHash() override = default;
4646

4747
bool evaluate(Transaction *transaction, const std::string &std) override;
4848

4949
bool init(const std::string &param, std::string *error) override;
5050
private:
5151
int m_threshold;
52-
struct fuzzy_hash_chunk *m_head;
52+
std::shared_ptr<fuzzy_hash_chunk> m_head;
5353
};
5454

5555
} // namespace operators

Diff for: src/request_body_processor/multipart.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ bool Multipart::process(const std::string& data, std::string *error,
16381638
}
16391639
} else { /* It looks like a boundary but */
16401640
/* we couldn't match it. */
1641-
char *p = NULL;
1641+
const char *p = NULL;
16421642

16431643
/* Check if an attempt to use quotes around the
16441644
* boundary was made. */

Diff for: src/rules_exceptions.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ bool RulesExceptions::loadUpdateActionById(double id,
5858

5959

6060
bool RulesExceptions::loadRemoveRuleByMsg(const std::string &msg,
61-
std::string *error) {
61+
const std::string *error) {
6262
m_remove_rule_by_msg.push_back(msg);
6363

6464
return true;
6565
}
6666

6767

6868
bool RulesExceptions::loadRemoveRuleByTag(const std::string &msg,
69-
std::string *error) {
69+
const std::string *error) {
7070
m_remove_rule_by_tag.push_back(msg);
7171

7272
return true;

0 commit comments

Comments
 (0)