Skip to content

Commit b564fdd

Browse files
Fix #12494 fuzzing crash in CheckAutoVariables::checkAutoVariableAssignment() (#6093)
1 parent 54f46d3 commit b564fdd

4 files changed

Lines changed: 14 additions & 20 deletions

File tree

lib/tokenize.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6658,7 +6658,10 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
66586658
}
66596659
if (!tokEnd || tokEnd->str() != ";") {
66606660
// No trailing ;
6661-
return tok;
6661+
if (tokStatement->isUpperCaseName())
6662+
unknownMacroError(tokStatement);
6663+
else
6664+
syntaxError(tokStatement);
66626665
}
66636666
}
66646667

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d o(i*a){n b;*a=&b;if(a)r{}}

test/testcondition.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,13 +2792,12 @@ class TestCondition : public TestFixture {
27922792
"}");
27932793
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str());
27942794

2795-
check("void f(int x) {\n" // #8217 - crash for incomplete code
2796-
" if (x > 100) { return; }\n"
2797-
" X(do);\n"
2798-
" if (x > 100) {}\n"
2799-
"}");
2800-
// TODO: we should probably throw unknownMacro InternalError. Complain that the macro X must be defined. We can't check the code well without the definition.
2801-
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'x>100' is always false\n", errout.str());
2795+
ASSERT_THROW(check("void f(int x) {\n" // #8217 - crash for incomplete code
2796+
" if (x > 100) { return; }\n"
2797+
" X(do);\n"
2798+
" if (x > 100) {}\n"
2799+
"}"),
2800+
InternalError);
28022801

28032802
check("void f(const int *i) {\n"
28042803
" if (!i) return;\n"

test/testtokenize.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,12 +1130,7 @@ class TestTokenizer : public TestFixture {
11301130
" for (int k=0; k<VectorSize; k++)"
11311131
" LOG_OUT(ID_Vector[k])"
11321132
"}";
1133-
const char expected[] =
1134-
"void f ( ) { "
1135-
"for ( int k = 0 ; k < VectorSize ; k ++ ) "
1136-
"LOG_OUT ( ID_Vector [ k ] ) "
1137-
"}";
1138-
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
1133+
ASSERT_THROW(tokenizeAndStringify(code), InternalError);
11391134
}
11401135

11411136
void ifAddBraces11() {
@@ -1358,16 +1353,12 @@ class TestTokenizer : public TestFixture {
13581353

13591354
{
13601355
const char code[] = "{ UNKNOWN_MACRO ( do ) ; while ( a -- ) ; }";
1361-
const char result[] = "{ UNKNOWN_MACRO ( do ) ; while ( a -- ) { ; } }";
1362-
1363-
ASSERT_EQUALS(result, tokenizeAndStringify(code));
1356+
ASSERT_THROW(tokenizeAndStringify(code), InternalError);
13641357
}
13651358

13661359
{
13671360
const char code[] = "{ UNKNOWN_MACRO ( do , foo ) ; while ( a -- ) ; }";
1368-
const char result[] = "{ UNKNOWN_MACRO ( do , foo ) ; while ( a -- ) { ; } }";
1369-
1370-
ASSERT_EQUALS(result, tokenizeAndStringify(code));
1361+
ASSERT_THROW(tokenizeAndStringify(code), InternalError);
13711362
}
13721363

13731364
{

0 commit comments

Comments
 (0)