Skip to content

Commit 0fe48ba

Browse files
authored
fix #14352: fuzzing crash (null-pointer-use) in Preprocessor::simplifyPragmaAsmPrivate() (danmar#8075)
1 parent 4fc4f01 commit 0fe48ba

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lib/preprocessor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ void Preprocessor::simplifyPragmaAsmPrivate(simplecpp::TokenList &tokenList)
10701070
continue;
10711071

10721072
const simplecpp::Token *endasm = tok3;
1073+
bool foundEndasm = false;
10731074
while ((endasm = endasm->next) != nullptr) {
10741075
if (endasm->op != '#' || sameline(endasm,endasm->previousSkipComments()))
10751076
continue;
@@ -1081,9 +1082,13 @@ void Preprocessor::simplifyPragmaAsmPrivate(simplecpp::TokenList &tokenList)
10811082
continue;
10821083
while (sameline(endasm,endasm3))
10831084
endasm = endasm->next;
1085+
foundEndasm = true;
10841086
break;
10851087
}
10861088

1089+
if (!foundEndasm)
1090+
throw InternalError(nullptr, "syntax error: missing #pragma endasm", InternalError::SYNTAX);
1091+
10871092
const simplecpp::Token * const tok4 = tok3->next;
10881093
tok->setstr("asm");
10891094
const_cast<simplecpp::Token *>(tok2)->setstr("(");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#pragma asm

test/testpreprocessor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ class TestPreprocessor : public TestFixture {
365365
TEST_CASE(standard);
366366

367367
TEST_CASE(writeLocations);
368+
369+
TEST_CASE(pragmaAsm);
368370
}
369371

370372
template<size_t size>
@@ -2804,6 +2806,12 @@ class TestPreprocessor : public TestFixture {
28042806
"} ;",
28052807
processed);
28062808
}
2809+
2810+
void pragmaAsm()
2811+
{
2812+
const char code[] = "#pragma asm";
2813+
ASSERT_THROW_INTERNAL(getcodeforcfg(settingsDefault, *this, code, "", "test.cpp"), InternalError::SYNTAX);
2814+
}
28072815
};
28082816

28092817
REGISTER_TEST(TestPreprocessor)

0 commit comments

Comments
 (0)