Skip to content

Commit

Permalink
Fix #344 fuzzing crash in simplecpp::preprocess() (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Oct 5, 2024
1 parent 6aa3ea1 commit d245956
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3480,7 +3480,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
inc2.takeTokens(inc1);
}

if (!inc2.empty() && inc2.cfront()->op == '<' && inc2.cback()->op == '>') {
if (!inc1.empty() && !inc2.empty() && inc2.cfront()->op == '<' && inc2.cback()->op == '>') {
TokenString hdr;
// TODO: Sometimes spaces must be added in the string
// Somehow preprocessToken etc must be told that the location should be source location not destination location
Expand Down
9 changes: 9 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,14 @@ static void missingHeader3()
ASSERT_EQUALS("", toString(outputList));
}

static void missingHeader4()
{
const char code[] = "#/**/include <>\n";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
ASSERT_EQUALS("file0,1,syntax_error,No header in #include\n", toString(outputList));
}

static void nestedInclude()
{
const char code[] = "#include \"test.h\"\n";
Expand Down Expand Up @@ -3057,6 +3065,7 @@ int main(int argc, char **argv)
TEST_CASE(missingHeader1);
TEST_CASE(missingHeader2);
TEST_CASE(missingHeader3);
TEST_CASE(missingHeader4);
TEST_CASE(nestedInclude);
TEST_CASE(systemInclude);

Expand Down

0 comments on commit d245956

Please sign in to comment.