Skip to content

Commit 18cdffd

Browse files
author
Felipe Zimmerle
committed
Encapsulates int[N] in a class to avoid compilation issues
Depending on the compiler, there may be a compilation issue with the usage of std::unique_ptr<int[]>. Therefore encapsulating it inside a regular class.
1 parent e3b9f7c commit 18cdffd

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

headers/modsecurity/rules_properties.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ class ConfigSet {
8282
};
8383

8484

85+
class UnicodeMapHolder {
86+
public:
87+
UnicodeMapHolder() {
88+
memset(m_data, -1, (sizeof(int)*65536));
89+
};
90+
91+
int& operator[](int index) { return m_data[index]; }
92+
int operator[](int index) const { return m_data[index]; }
93+
94+
int at(int index) const { return m_data[index]; }
95+
void change(int i, int a) { m_data[i] = a; }
96+
97+
int m_data[65536];
98+
};
99+
100+
85101
class RulesProperties;
86102
class ConfigUnicodeMap {
87103
public:
@@ -106,7 +122,7 @@ class ConfigUnicodeMap {
106122

107123
bool m_set;
108124
double m_unicodeCodePage;
109-
std::shared_ptr<int[]> m_unicodeMapTable;
125+
std::shared_ptr<modsecurity::UnicodeMapHolder> m_unicodeMapTable;
110126
};
111127

112128

src/actions/transformations/url_decode_uni.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int UrlDecodeUni::inplace(unsigned char *input, uint64_t input_len,
109109

110110
if (Code >= 0 && Code <= 65535) {
111111
Rules *r = t->m_rules;
112-
hmap = r->m_unicodeMapTable.m_unicodeMapTable[Code];
112+
hmap = r->m_unicodeMapTable.m_unicodeMapTable->at(Code);
113113
}
114114
}
115115

src/rules_properties.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,17 @@ void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage,
4040
driver->m_unicodeMapTable.m_set = true;
4141
driver->m_unicodeMapTable.m_unicodeCodePage = configCodePage;
4242

43-
std::unique_ptr<int[]> a(new int[65536], std::default_delete<int[]>());
44-
driver->m_unicodeMapTable.m_unicodeMapTable = std::move(a);
45-
memset(driver->m_unicodeMapTable.m_unicodeMapTable.get(), -1,
46-
(sizeof(int)*65536));
43+
driver->m_unicodeMapTable.m_unicodeMapTable.reset(new modsecurity::UnicodeMapHolder());
4744

4845
/* Setting some unicode values - http://tools.ietf.org/html/rfc3490#section-3.1 */
4946
/* Set 0x3002 -> 0x2e */
50-
driver->m_unicodeMapTable.m_unicodeMapTable[0x3002] = 0x2e;
47+
driver->m_unicodeMapTable.m_unicodeMapTable->change(0x3002, 0x2e);
5148
/* Set 0xFF61 -> 0x2e */
52-
driver->m_unicodeMapTable.m_unicodeMapTable[0xff61] = 0x2e;
49+
driver->m_unicodeMapTable.m_unicodeMapTable->change(0xff61, 0x2e);
5350
/* Set 0xFF0E -> 0x2e */
54-
driver->m_unicodeMapTable.m_unicodeMapTable[0xff0e] = 0x2e;
51+
driver->m_unicodeMapTable.m_unicodeMapTable->change(0xff0e, 0x2e);
5552
/* Set 0x002E -> 0x2e */
56-
driver->m_unicodeMapTable.m_unicodeMapTable[0x002e] = 0x2e;
53+
driver->m_unicodeMapTable.m_unicodeMapTable->change(0x002e, 0x2e);
5754

5855

5956
std::ifstream file_stream(f, std::ios::in | std::ios::binary);
@@ -106,7 +103,7 @@ void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage,
106103
sscanf(ucode, "%x", &code);
107104
sscanf(hmap, "%x", &Map);
108105
if (code >= 0 && code <= 65535) {
109-
driver->m_unicodeMapTable.m_unicodeMapTable[code] = Map;
106+
driver->m_unicodeMapTable.m_unicodeMapTable->change(code, Map);
110107
}
111108

112109
free(mapping);

0 commit comments

Comments
 (0)