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.
This commit is contained in:
Felipe Zimmerle 2018-11-01 10:21:41 -03:00
parent e3b9f7c913
commit 18cdffdbca
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
3 changed files with 24 additions and 11 deletions

View File

@ -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<int[]> m_unicodeMapTable;
std::shared_ptr<modsecurity::UnicodeMapHolder> m_unicodeMapTable;
};

View File

@ -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);
}
}

View File

@ -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<int[]> a(new int[65536], std::default_delete<int[]>());
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);