Skip to content

Commit 2d11ff1

Browse files
defanatorFelipe Zimmerle
authored andcommitted
Implemented merge() method for ConfigInt, ConfigDouble, ConfigString
This change makes the following directives to be merged properly: SecRequestBodyLimit SecResponseBodyLimit SecUploadFileLimit SecUploadFileMode SecUploadDir SecTmpDir SecArgumentSeparator SecWebAppId SecHttpBlKey
1 parent 78b7fa4 commit 2d11ff1

File tree

1 file changed

+36
-43
lines changed

1 file changed

+36
-43
lines changed

headers/modsecurity/rules_properties.h

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ class ConfigInt {
5454
ConfigInt() : m_set(false), m_value(0) { }
5555
bool m_set;
5656
int m_value;
57+
58+
void merge(ConfigInt *from) {
59+
if (m_set == true || from->m_set == false) {
60+
return;
61+
}
62+
m_set = true;
63+
m_value = from->m_value;
64+
return;
65+
}
5766
};
5867

5968

@@ -62,6 +71,15 @@ class ConfigDouble {
6271
ConfigDouble() : m_set(false), m_value(0) { }
6372
bool m_set;
6473
double m_value;
74+
75+
void merge(ConfigDouble *from) {
76+
if (m_set == true || from->m_set == false) {
77+
return;
78+
}
79+
m_set = true;
80+
m_value = from->m_value;
81+
return;
82+
}
6583
};
6684

6785

@@ -70,6 +88,15 @@ class ConfigString {
7088
ConfigString() : m_set(false), m_value("") { }
7189
bool m_set;
7290
std::string m_value;
91+
92+
void merge(ConfigString *from) {
93+
if (m_set == true || from->m_set == false) {
94+
return;
95+
}
96+
m_set = true;
97+
m_value = from->m_value;
98+
return;
99+
}
73100
};
74101

75102

@@ -341,15 +368,8 @@ class RulesProperties {
341368
to->m_tmpSaveUploadedFiles = from->m_tmpSaveUploadedFiles;
342369
}
343370

344-
if (from->m_requestBodyLimit.m_set == true) {
345-
to->m_requestBodyLimit.m_value = from->m_requestBodyLimit.m_value;
346-
to->m_requestBodyLimit.m_set = true;
347-
}
348-
349-
if (from->m_responseBodyLimit.m_set == true) {
350-
to->m_responseBodyLimit.m_value = from->m_responseBodyLimit.m_value;
351-
to->m_responseBodyLimit.m_set = true;
352-
}
371+
to->m_requestBodyLimit.merge(&from->m_requestBodyLimit);
372+
to->m_responseBodyLimit.merge(&from->m_responseBodyLimit);
353373

354374
if (from->m_requestBodyLimitAction != PropertyNotSetBodyLimitAction) {
355375
to->m_requestBodyLimitAction = from->m_requestBodyLimitAction;
@@ -359,45 +379,18 @@ class RulesProperties {
359379
to->m_responseBodyLimitAction = from->m_responseBodyLimitAction;
360380
}
361381

362-
if (from->m_uploadFileLimit.m_set == true) {
363-
to->m_uploadFileLimit.m_value = from->m_uploadFileLimit.m_value;
364-
to->m_uploadFileLimit.m_set = true;
365-
}
382+
to->m_uploadFileLimit.merge(&from->m_uploadFileLimit);
383+
to->m_uploadFileMode.merge(&from->m_uploadFileMode);
384+
to->m_uploadDirectory.merge(&from->m_uploadDirectory);
385+
to->m_uploadTmpDirectory.merge(&from->m_uploadTmpDirectory);
366386

367-
if (from->m_uploadFileMode.m_set == true) {
368-
to->m_uploadFileMode.m_value = from->m_uploadFileMode.m_value;
369-
to->m_uploadFileMode.m_set = true;
370-
}
387+
to->m_secArgumentSeparator.merge(&from->m_secArgumentSeparator);
371388

372-
if (from->m_uploadDirectory.m_set == true) {
373-
to->m_uploadDirectory.m_value = from->m_uploadDirectory.m_value;
374-
to->m_uploadDirectory.m_set = true;
375-
}
376-
377-
if (from->m_uploadTmpDirectory.m_set == true) {
378-
to->m_uploadTmpDirectory.m_value = \
379-
from->m_uploadTmpDirectory.m_value;
380-
to->m_uploadTmpDirectory.m_set = true;
381-
}
382-
383-
if (from->m_secArgumentSeparator.m_set == true) {
384-
to->m_secArgumentSeparator.m_value = \
385-
from->m_secArgumentSeparator.m_value;
386-
to->m_secArgumentSeparator.m_set = true;
387-
}
388-
389-
if (from->m_secWebAppId.m_set == true) {
390-
to->m_secWebAppId.m_value = \
391-
from->m_secWebAppId.m_value;
392-
to->m_secWebAppId.m_set = true;
393-
}
389+
to->m_secWebAppId.merge(&from->m_secWebAppId);
394390

395391
to->m_unicodeMapTable.merge(&from->m_unicodeMapTable);
396392

397-
if (from->m_httpblKey.m_set == true) {
398-
to->m_httpblKey.m_value = from->m_httpblKey.m_value;
399-
to->m_httpblKey.m_set = from->m_httpblKey.m_set;
400-
}
393+
to->m_httpblKey.merge(&from->m_httpblKey);
401394

402395
to->m_exceptions.merge(&from->m_exceptions);
403396

0 commit comments

Comments
 (0)