diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 273d8df6123..3b69c31085d 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -469,6 +469,8 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::setstr() == "==" || cond->str() == "<=" || cond->str() == ">=") { + if (!cond->next) + break; if (cond->next->number) { const simplecpp::Token *dtok = cond->previous; if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str()) == defined.end() && undefined.find(dtok->str()) == undefined.end()) @@ -477,6 +479,8 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::setop == '<' || cond->op == '>') { + if (!cond->next) + break; if (cond->next->number) { const simplecpp::Token *dtok = cond->previous; if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str()) == defined.end() && undefined.find(dtok->str()) == undefined.end()) { diff --git a/test/cli/fuzz-crash/crash-41fefbc326c326d02c9e1fe315280ddd326e8a5b b/test/cli/fuzz-crash/crash-41fefbc326c326d02c9e1fe315280ddd326e8a5b new file mode 100644 index 00000000000..b090d2bf345 --- /dev/null +++ b/test/cli/fuzz-crash/crash-41fefbc326c326d02c9e1fe315280ddd326e8a5b @@ -0,0 +1 @@ +#if< \ No newline at end of file diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index d072ebbf2e3..6846d49ff30 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -343,6 +343,8 @@ class TestPreprocessor : public TestFixture { TEST_CASE(getConfigsAndCodeIssue14317); TEST_CASE(getConfigsMostGeneralConfigIssue14317); + TEST_CASE(getConfigsInvalid); // #14732 + TEST_CASE(if_sizeof); TEST_CASE(invalid_ifs); // #5909 @@ -2715,6 +2717,33 @@ class TestPreprocessor : public TestFixture { ASSERT_EQUALS("\nX\nY=Y\nZ\n", getConfigsStr(filedata)); } + void getConfigsInvalid() { // #14732 + { + const char filedata[] = "#if<"; + ASSERT_EQUALS("\n", getConfigsStr(filedata)); + } + { + const char filedata[] = "#if>"; + ASSERT_EQUALS("\n", getConfigsStr(filedata)); + } + { + const char filedata[] = "#if=="; + ASSERT_EQUALS("\n", getConfigsStr(filedata)); + } + { + const char filedata[] = "#if<="; + ASSERT_EQUALS("\n", getConfigsStr(filedata)); + } + { + const char filedata[] = "#if>="; + ASSERT_EQUALS("\n", getConfigsStr(filedata)); + } + { + const char filedata[] = "#if!"; + ASSERT_EQUALS("\n", getConfigsStr(filedata)); + } + } + void if_sizeof() { // #4071 const char code[] = "#if sizeof(unsigned short) == 2\n" "Fred & Wilma\n"