Skip to content

Commit 1ad9525

Browse files
author
Felipe Zimmerle
committed
Avoids unicode initialization on every rules block
ModSecurity-nginx/#67 ModSecurity/#1563
1 parent 20edf9a commit 1ad9525

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

Diff for: CHANGES

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
v3.0.????? - ?
33
---------------------------
44

5+
- Avoids unicode initialization on every rules object
6+
[Issue #1563 - @zimmerle, @Tiki-God, @sethinsd, @Cloaked9000, @AnoopAlias,
7+
@intelbg]
58
- Makes clear to the user whenever the audit log is empty due to missing
69
JSON support.
710
[Issue #1585 - @zimmerle]

Diff for: headers/modsecurity/rules.h

+4-12
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,23 @@ namespace Parser {
4040
class Driver;
4141
}
4242

43+
4344
/** @ingroup ModSecurity_CPP_API */
4445
class Rules : public RulesProperties {
4546
public:
4647
Rules()
4748
: RulesProperties(new DebugLog()),
4849
unicode_codepage(0),
4950
m_referenceCount(0),
50-
m_secmarker_skipped(0) {
51-
unicode_map_table = reinterpret_cast<int *>(
52-
malloc(sizeof(int)*65536));
53-
memset(unicode_map_table, -1, (sizeof(int)*65536));
54-
}
51+
m_secmarker_skipped(0) { }
5552

5653
explicit Rules(DebugLog *customLog)
5754
: RulesProperties(customLog),
5855
unicode_codepage(0),
5956
m_referenceCount(0),
60-
m_secmarker_skipped(0) {
61-
unicode_map_table = reinterpret_cast<int *>(
62-
malloc(sizeof(int)*65536));
63-
memset(unicode_map_table, -1, (sizeof(int)*65536));
64-
}
57+
m_secmarker_skipped(0) { }
6558

66-
~Rules();
59+
~Rules() { }
6760

6861
void incrementReferenceCount(void);
6962
void decrementReferenceCount(void);
@@ -83,7 +76,6 @@ class Rules : public RulesProperties {
8376

8477
void debug(int level, std::string message);
8578

86-
int *unicode_map_table;
8779
int64_t unicode_codepage;
8880

8981
private:

Diff for: headers/modsecurity/rules_properties.h

+14
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ class ConfigSet {
7979
std::set<std::string> m_value;
8080
};
8181

82+
83+
class ConfigUnicodeMap {
84+
public:
85+
ConfigUnicodeMap() : m_set(false), m_unicode_map_table(NULL) { }
86+
bool m_set;
87+
int *m_unicode_map_table;
88+
};
89+
8290
class RulesProperties {
8391
public:
8492
RulesProperties() :
@@ -332,6 +340,11 @@ class RulesProperties {
332340
from->m_secArgumentSeparator.m_value;
333341
}
334342

343+
if (from->m_unicodeMapTable.m_set == true) {
344+
to->m_unicodeMapTable.m_unicode_map_table = \
345+
from->m_unicodeMapTable.m_unicode_map_table;
346+
}
347+
335348
if (from->m_httpblKey.m_set == true) {
336349
to->m_httpblKey.m_value = from->m_httpblKey.m_value;
337350
to->m_httpblKey.m_set = from->m_httpblKey.m_set;
@@ -469,6 +482,7 @@ class RulesProperties {
469482
ConfigString m_secArgumentSeparator;
470483
std::vector<actions::Action *> m_defaultActions[8];
471484
std::vector<modsecurity::Rule *> m_rules[8];
485+
ConfigUnicodeMap m_unicodeMapTable;
472486
};
473487

474488
#endif

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ int UrlDecodeUni::inplace(unsigned char *input, uint64_t input_len,
8787
fact = 1;
8888

8989
if (transaction
90-
&& transaction->m_rules->unicode_map_table != NULL
90+
&& transaction->m_rules->m_unicodeMapTable.m_set == true
91+
&& transaction->m_rules->m_unicodeMapTable.m_unicode_map_table != NULL
9192
&& transaction->m_rules->unicode_codepage > 0) {
9293
for (j = 5; j >= 2; j--) {
9394
if (isxdigit((input[i+j]))) {
@@ -105,7 +106,7 @@ int UrlDecodeUni::inplace(unsigned char *input, uint64_t input_len,
105106

106107
if (Code >= 0 && Code <= 65535) {
107108
Rules *r = transaction->m_rules;
108-
hmap = r->unicode_map_table[Code];
109+
hmap = r->m_unicodeMapTable.m_unicode_map_table[Code];
109110
}
110111
}
111112

Diff for: src/rules.cc

-6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ void Rules::decrementReferenceCount(void) {
7777
}
7878

7979

80-
Rules::~Rules() {
81-
free(unicode_map_table);
82-
unicode_map_table = NULL;
83-
}
84-
85-
8680
/**
8781
* @name loadFromUri
8882
* @brief load rules from a give uri

0 commit comments

Comments
 (0)