Skip to content

Commit e3b9f7c

Browse files
victorhoraFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Fix SecUnicodeMapFile support
Makes SecUnicodeMapFile read the file and adjust transformation to use the right variable.
1 parent 84ece3e commit e3b9f7c

File tree

12 files changed

+5812
-5734
lines changed

12 files changed

+5812
-5734
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ v3.0.3 - YYYY-MMM-DD (to be released)
1414
- Changes debuglogs schema to avoid unecessary str allocation
1515
[0xb2840 - @zimmerle]
1616
- Fix the SecUnicodeMapFile and SecUnicodeCodePage
17-
[0x3094d - @zimmerle]
17+
[0x3094d - @zimmerle, @victorhora]
1818
- Changes the timing to save the rule message
1919
[0xca270 - @zimmerle]
2020
- Fix crash in msc_rules_add_file() when using disruptive action in chain

headers/modsecurity/rules_properties.h

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <vector>
2222
#include <list>
2323
#include <set>
24+
#include <cstring>
2425
#endif
2526

2627

@@ -34,6 +35,7 @@
3435
#include "modsecurity/actions/action.h"
3536
#include "modsecurity/audit_log.h"
3637

38+
#define CODEPAGE_SEPARATORS " \t\n\r"
3739

3840
#ifdef __cplusplus
3941

@@ -80,14 +82,34 @@ class ConfigSet {
8082
};
8183

8284

85+
class RulesProperties;
8386
class ConfigUnicodeMap {
8487
public:
85-
ConfigUnicodeMap() : m_set(false), m_unicode_map_table(NULL), m_unicode_codepage(0) { }
88+
ConfigUnicodeMap() : m_set(false),
89+
m_unicodeCodePage(0),
90+
m_unicodeMapTable(NULL) { }
91+
92+
static void loadConfig(std::string f, double codePage,
93+
RulesProperties *driver, std::string *errg);
94+
95+
void merge(ConfigUnicodeMap *from) {
96+
if (from->m_set == false) {
97+
return;
98+
}
99+
100+
m_set = true;
101+
m_unicodeCodePage = from->m_unicodeCodePage;
102+
m_unicodeMapTable = from->m_unicodeMapTable;
103+
104+
return;
105+
}
106+
86107
bool m_set;
87-
int *m_unicode_map_table;
88-
unsigned long int m_unicode_codepage;
108+
double m_unicodeCodePage;
109+
std::shared_ptr<int[]> m_unicodeMapTable;
89110
};
90111

112+
91113
class RulesProperties {
92114
public:
93115
RulesProperties() :
@@ -350,13 +372,7 @@ class RulesProperties {
350372
to->m_secWebAppId.m_set = true;
351373
}
352374

353-
if (from->m_unicodeMapTable.m_set == true) {
354-
to->m_unicodeMapTable.m_unicode_map_table = \
355-
from->m_unicodeMapTable.m_unicode_map_table;
356-
to->m_unicodeMapTable.m_unicode_codepage = \
357-
from->m_unicodeMapTable.m_unicode_codepage;
358-
to->m_unicodeMapTable.m_set = true;
359-
}
375+
to->m_unicodeMapTable.merge(&from->m_unicodeMapTable);
360376

361377
if (from->m_httpblKey.m_set == true) {
362378
to->m_httpblKey.m_value = from->m_httpblKey.m_value;
@@ -508,6 +524,7 @@ class RulesProperties {
508524
ConfigUnicodeMap m_unicodeMapTable;
509525
};
510526

527+
511528
#endif
512529

513530
#ifdef __cplusplus

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ libmodsecurity_la_SOURCES = \
279279
rule_script.cc \
280280
unique_id.cc \
281281
rules_exceptions.cc \
282+
rules_properties.cc \
282283
${BODY_PROCESSORS} \
283284
${ACTIONS} \
284285
${ENGINES} \

src/actions/transformations/url_decode_uni.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
#include "modsecurity/transaction.h"
2929
#include "src/actions/transformations/transformation.h"
3030
#include "src/utils/string.h"
31+
#include "src/utils/system.h"
3132
#include "modsecurity/rules.h"
33+
#include "modsecurity/rules_properties.h"
34+
3235

3336
namespace modsecurity {
3437
namespace actions {
@@ -88,8 +91,8 @@ int UrlDecodeUni::inplace(unsigned char *input, uint64_t input_len,
8891

8992
if (t
9093
&& t->m_rules->m_unicodeMapTable.m_set == true
91-
&& t->m_rules->m_unicodeMapTable.m_unicode_map_table != NULL
92-
&& t->m_rules->unicode_codepage > 0) {
94+
&& t->m_rules->m_unicodeMapTable.m_unicodeMapTable != NULL
95+
&& t->m_rules->m_unicodeMapTable.m_unicodeCodePage > 0) {
9396
for (j = 5; j >= 2; j--) {
9497
if (isxdigit((input[i+j]))) {
9598
if (input[i+j] >= 97) {
@@ -106,7 +109,7 @@ int UrlDecodeUni::inplace(unsigned char *input, uint64_t input_len,
106109

107110
if (Code >= 0 && Code <= 65535) {
108111
Rules *r = t->m_rules;
109-
hmap = r->m_unicodeMapTable.m_unicode_map_table[Code];
112+
hmap = r->m_unicodeMapTable.m_unicodeMapTable[Code];
110113
}
111114
}
112115

src/actions/transformations/url_decode_uni.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
#include <string>
1717

1818
#include "modsecurity/actions/action.h"
19+
#include "modsecurity/rules_properties.h"
1920
#include "src/actions/transformations/transformation.h"
2021

2122
#ifndef SRC_ACTIONS_TRANSFORMATIONS_URL_DECODE_UNI_H_
2223
#define SRC_ACTIONS_TRANSFORMATIONS_URL_DECODE_UNI_H_
2324

25+
2426
#ifdef __cplusplus
2527
namespace modsecurity {
2628
class Transaction;
27-
2829
namespace actions {
2930
namespace transformations {
3031

0 commit comments

Comments
 (0)