Skip to content

Commit 2047c30

Browse files
authored
fix #14077: fuzzing crash (assert) in Token::update_property_info() (danmar#7808)
1 parent 799c7c0 commit 2047c30

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

lib/token.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void Token::update_property_info()
153153
if ((MathLib::isInt(mStr) || MathLib::isFloat(mStr)) && mStr.find('_') == std::string::npos)
154154
tokType(eNumber);
155155
else
156-
tokType(eName); // assume it is a user defined literal
156+
tokType(eLiteral); // assume it is a user defined literal
157157
} else if (mStr == "=" || mStr == "<<=" || mStr == ">>=" ||
158158
(mStr.size() == 2U && mStr[1] == '=' && std::strchr("+-*/%&^|", mStr[0])))
159159
tokType(eAssignmentOp);

lib/tokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,7 @@ void Tokenizer::findGarbageCode() const
88698869
!Token::simpleMatch(tok->previous(), ".") &&
88708870
!Token::simpleMatch(tok->next(), ".") &&
88718871
!Token::Match(tok->previous(), "{|, . %name% =|.|[|{") &&
8872+
!(tok->previous() && tok->previous()->isLiteral()) &&
88728873
!Token::Match(tok->previous(), ", . %name%")) {
88738874
if (!Token::Match(tok->previous(), "%name%|)|]|>|}"))
88748875
syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1));
@@ -9877,7 +9878,7 @@ void Tokenizer::simplifyAsm()
98779878
Token *endasm = tok->next();
98789879
const Token *firstSemiColon = nullptr;
98799880
int comment = 0;
9880-
while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && endasm->linenr() == comment)) {
9881+
while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && (endasm->isLiteral() || endasm->linenr() == comment))) {
98819882
if (Token::Match(endasm, "_asm|__asm|__endasm"))
98829883
break;
98839884
if (endasm->str() == ";") {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_ 1p;

test/testsymboldatabase.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ class TestSymbolDatabase : public TestFixture {
624624
TEST_CASE(smartPointerLookupCtor); // #13719);
625625

626626
TEST_CASE(stdintFunction);
627+
628+
TEST_CASE(userDefinedLiteral);
627629
}
628630

629631
void array() {
@@ -11327,6 +11329,14 @@ class TestSymbolDatabase : public TestFixture {
1132711329
ASSERT_EQUALS(tok->next()->valueType()->sign, ValueType::Sign::UNSIGNED);
1132811330
ASSERT_EQUALS(tok->next()->valueType()->type, ValueType::Type::INT);
1132911331
}
11332+
11333+
void userDefinedLiteral() {
11334+
GET_SYMBOL_DB("_ 1p;");
11335+
const Token *x = Token::findsimplematch(tokenizer.tokens(), "1p");
11336+
ASSERT(x);
11337+
ASSERT(!x->varId());
11338+
ASSERT(!x->variable());
11339+
}
1133011340
};
1133111341

1133211342
REGISTER_TEST(TestSymbolDatabase)

test/testtoken.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ class TestToken : public TestFixture {
13031303
assert_tok("0.0", Token::Type::eNumber);
13041304
assert_tok("0x0.3p10", Token::Type::eNumber);
13051305
assert_tok("0z", Token::Type::eNumber); // TODO: not a valid number
1306-
assert_tok("0_km", Token::Type::eName); // user literal
1306+
assert_tok("0_km", Token::Type::eLiteral); // user literal
13071307
assert_tok("=", Token::Type::eAssignmentOp);
13081308
assert_tok("<<=", Token::Type::eAssignmentOp);
13091309
assert_tok(">>=", Token::Type::eAssignmentOp);

0 commit comments

Comments
 (0)