Skip to content

Commit 17f3bb0

Browse files
authored
Merge pull request #2800 from martinhsv/v3/master
Correct whitespace handling for Include directive
2 parents 0840a29 + 53cf6eb commit 17f3bb0

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

Diff for: CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.x.y - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Correct whitespace handling for Include directive
5+
[Issue #2800 - @877509395, @martinhsv]
46

57

68
v3.0.8 - 2022-Sep-07

Diff for: src/parser/seclang-scanner.cc

+11-10
Original file line numberDiff line numberDiff line change
@@ -5104,7 +5104,7 @@ static const flex_int16_t yy_rule_linenum[544] =
51045104
1179, 1180, 1181, 1182, 1184, 1185, 1186, 1187, 1189, 1190,
51055105
1191, 1192, 1194, 1196, 1197, 1199, 1200, 1201, 1202, 1204,
51065106
1209, 1210, 1211, 1215, 1216, 1217, 1222, 1224, 1225, 1226,
5107-
1245, 1272, 1302
5107+
1245, 1273, 1303
51085108
} ;
51095109

51105110
/* The intent behind this definition is that it'll catch
@@ -8530,7 +8530,8 @@ YY_RULE_SETUP
85308530
#line 1245 "seclang-scanner.ll"
85318531
{
85328532
std::string err;
8533-
const char *file = strchr(yytext, ' ') + 1;
8533+
const char *tmpStr = yytext + strlen("include");
8534+
const char *file = tmpStr + strspn( tmpStr, " \t");
85348535
std::string fi = modsecurity::utils::find_resource(file, *driver.loc.back()->end.filename, &err);
85358536
if (fi.empty() == true) {
85368537
BEGIN(INITIAL);
@@ -8557,12 +8558,12 @@ YY_RULE_SETUP
85578558
YY_BREAK
85588559
case 542:
85598560
YY_RULE_SETUP
8560-
#line 1272 "seclang-scanner.ll"
8561+
#line 1273 "seclang-scanner.ll"
85618562
{
85628563
std::string err;
8563-
const char *file = strchr(yytext, ' ') + 1;
8564-
char *f = strdup(file + 1);
8565-
f[strlen(f)-1] = '\0';
8564+
const char *tmpStr = yytext + strlen("include");
8565+
const char *file = tmpStr + strspn( tmpStr, " \t");
8566+
char *f = strdup(file);
85668567
std::string fi = modsecurity::utils::find_resource(f, *driver.loc.back()->end.filename, &err);
85678568
if (fi.empty() == true) {
85688569
BEGIN(INITIAL);
@@ -8591,7 +8592,7 @@ YY_RULE_SETUP
85918592
case 543:
85928593
/* rule 543 can match eol */
85938594
YY_RULE_SETUP
8594-
#line 1302 "seclang-scanner.ll"
8595+
#line 1303 "seclang-scanner.ll"
85958596
{
85968597
HttpsClient c;
85978598
std::string key;
@@ -8629,10 +8630,10 @@ YY_RULE_SETUP
86298630
YY_BREAK
86308631
case 544:
86318632
YY_RULE_SETUP
8632-
#line 1338 "seclang-scanner.ll"
8633+
#line 1339 "seclang-scanner.ll"
86338634
ECHO;
86348635
YY_BREAK
8635-
#line 8636 "seclang-scanner.cc"
8636+
#line 8637 "seclang-scanner.cc"
86368637

86378638
case YY_END_OF_BUFFER:
86388639
{
@@ -9737,7 +9738,7 @@ void yyfree (void * ptr )
97379738

97389739
/* %ok-for-header */
97399740

9740-
#line 1338 "seclang-scanner.ll"
9741+
#line 1339 "seclang-scanner.ll"
97419742

97429743

97439744
namespace modsecurity {

Diff for: src/parser/seclang-scanner.ll

+5-4
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,8 @@ EQUALS_MINUS (?i:=\-)
12431243
12441244
{CONFIG_INCLUDE}[ \t]+{CONFIG_VALUE_PATH} {
12451245
std::string err;
1246-
const char *file = strchr(yytext, ' ') + 1;
1246+
const char *tmpStr = yytext + strlen("include");
1247+
const char *file = tmpStr + strspn( tmpStr, " \t");
12471248
std::string fi = modsecurity::utils::find_resource(file, *driver.loc.back()->end.filename, &err);
12481249
if (fi.empty() == true) {
12491250
BEGIN(INITIAL);
@@ -1270,9 +1271,9 @@ EQUALS_MINUS (?i:=\-)
12701271
12711272
{CONFIG_INCLUDE}[ \t]+["]{CONFIG_VALUE_PATH}["] {
12721273
std::string err;
1273-
const char *file = strchr(yytext, ' ') + 1;
1274-
char *f = strdup(file + 1);
1275-
f[strlen(f)-1] = '\0';
1274+
const char *tmpStr = yytext + strlen("include");
1275+
const char *file = tmpStr + strspn( tmpStr, " \t");
1276+
char *f = strdup(file);
12761277
std::string fi = modsecurity::utils::find_resource(f, *driver.loc.back()->end.filename, &err);
12771278
if (fi.empty() == true) {
12781279
BEGIN(INITIAL);

0 commit comments

Comments
 (0)