diff --git a/headers/modsecurity/rules_properties.h b/headers/modsecurity/rules_properties.h index 8cb7cae3..78cf8add 100644 --- a/headers/modsecurity/rules_properties.h +++ b/headers/modsecurity/rules_properties.h @@ -82,6 +82,22 @@ class ConfigSet { }; +class UnicodeMapHolder { + public: + UnicodeMapHolder() { + memset(m_data, -1, (sizeof(int)*65536)); + }; + + int& operator[](int index) { return m_data[index]; } + int operator[](int index) const { return m_data[index]; } + + int at(int index) const { return m_data[index]; } + void change(int i, int a) { m_data[i] = a; } + + int m_data[65536]; +}; + + class RulesProperties; class ConfigUnicodeMap { public: @@ -106,7 +122,7 @@ class ConfigUnicodeMap { bool m_set; double m_unicodeCodePage; - std::shared_ptr m_unicodeMapTable; + std::shared_ptr m_unicodeMapTable; }; diff --git a/src/actions/transformations/url_decode_uni.cc b/src/actions/transformations/url_decode_uni.cc index 13ed17b8..88de1a4e 100644 --- a/src/actions/transformations/url_decode_uni.cc +++ b/src/actions/transformations/url_decode_uni.cc @@ -109,7 +109,7 @@ int UrlDecodeUni::inplace(unsigned char *input, uint64_t input_len, if (Code >= 0 && Code <= 65535) { Rules *r = t->m_rules; - hmap = r->m_unicodeMapTable.m_unicodeMapTable[Code]; + hmap = r->m_unicodeMapTable.m_unicodeMapTable->at(Code); } } diff --git a/src/rules_properties.cc b/src/rules_properties.cc index 488e70fd..78f0e9d1 100644 --- a/src/rules_properties.cc +++ b/src/rules_properties.cc @@ -40,20 +40,17 @@ void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage, driver->m_unicodeMapTable.m_set = true; driver->m_unicodeMapTable.m_unicodeCodePage = configCodePage; - std::unique_ptr a(new int[65536], std::default_delete()); - driver->m_unicodeMapTable.m_unicodeMapTable = std::move(a); - memset(driver->m_unicodeMapTable.m_unicodeMapTable.get(), -1, - (sizeof(int)*65536)); + driver->m_unicodeMapTable.m_unicodeMapTable.reset(new modsecurity::UnicodeMapHolder()); /* Setting some unicode values - http://tools.ietf.org/html/rfc3490#section-3.1 */ /* Set 0x3002 -> 0x2e */ - driver->m_unicodeMapTable.m_unicodeMapTable[0x3002] = 0x2e; + driver->m_unicodeMapTable.m_unicodeMapTable->change(0x3002, 0x2e); /* Set 0xFF61 -> 0x2e */ - driver->m_unicodeMapTable.m_unicodeMapTable[0xff61] = 0x2e; + driver->m_unicodeMapTable.m_unicodeMapTable->change(0xff61, 0x2e); /* Set 0xFF0E -> 0x2e */ - driver->m_unicodeMapTable.m_unicodeMapTable[0xff0e] = 0x2e; + driver->m_unicodeMapTable.m_unicodeMapTable->change(0xff0e, 0x2e); /* Set 0x002E -> 0x2e */ - driver->m_unicodeMapTable.m_unicodeMapTable[0x002e] = 0x2e; + driver->m_unicodeMapTable.m_unicodeMapTable->change(0x002e, 0x2e); std::ifstream file_stream(f, std::ios::in | std::ios::binary); @@ -106,7 +103,7 @@ void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage, sscanf(ucode, "%x", &code); sscanf(hmap, "%x", &Map); if (code >= 0 && code <= 65535) { - driver->m_unicodeMapTable.m_unicodeMapTable[code] = Map; + driver->m_unicodeMapTable.m_unicodeMapTable->change(code, Map); } free(mapping);