Skip to content

Commit c5c02ff

Browse files
authored
fixed fuzzing crash in simplecpp::Macro::expandToken() (#345)
1 parent 6547bf7 commit c5c02ff

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

simplecpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ namespace simplecpp {
19841984
if (paren == 0)
19851985
return tok->next->next;
19861986
tok = tok->next;
1987-
if (parametertokens.front()->next->str() != ")" && parametertokens.size() > args.size())
1987+
if (parametertokens.size() > args.size() && parametertokens.front()->next->str() != ")")
19881988
tok = expandToken(output, loc, tok, macros, expandedmacros, parametertokens)->previous;
19891989
}
19901990
}

test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,15 @@ static void token()
27142714
ASSERT_TOKEN("+22", false, true, false);
27152715
}
27162716

2717+
static void fuzz_crash()
2718+
{
2719+
{
2720+
const char code[] = "#define n __VA_OPT__(u\n"
2721+
"n\n";
2722+
(void)preprocess(code, simplecpp::DUI()); // do not crash
2723+
}
2724+
}
2725+
27172726
int main(int argc, char **argv)
27182727
{
27192728
TEST_CASE(backslash);
@@ -2940,5 +2949,7 @@ int main(int argc, char **argv)
29402949

29412950
TEST_CASE(token);
29422951

2952+
TEST_CASE(fuzz_crash);
2953+
29432954
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
29442955
}

0 commit comments

Comments
 (0)