moc: Fix a crash with malformed input
Do not increment 'data' past the buffer in case of invalid token. Remove the left over qDebug so we can make a test. Task-number: QTBUG-54609 Change-Id: I8f0dd3381fbdea3f07d3c05c9a44a16d92538117 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>bb10
parent
9a00ae8e24
commit
34de4f6a15
|
|
@ -188,7 +188,8 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso
|
|||
token = keywords[state].ident;
|
||||
|
||||
if (token == NOTOKEN) {
|
||||
++data;
|
||||
if (*data)
|
||||
++data;
|
||||
// an error really, but let's ignore this input
|
||||
// to not confuse moc later. However in pre-processor
|
||||
// only mode let's continue.
|
||||
|
|
@ -361,7 +362,6 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso
|
|||
++data;
|
||||
continue;
|
||||
}
|
||||
|
||||
int nextindex = pp_keywords[state].next;
|
||||
int next = 0;
|
||||
if (*data == pp_keywords[state].defchar)
|
||||
|
|
@ -380,7 +380,8 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso
|
|||
|
||||
switch (token) {
|
||||
case NOTOKEN:
|
||||
++data;
|
||||
if (*data)
|
||||
++data;
|
||||
break;
|
||||
case PP_DEFINE:
|
||||
mode = PrepareDefine;
|
||||
|
|
@ -1251,7 +1252,6 @@ void Preprocessor::parseDefineArguments(Macro *m)
|
|||
error("missing ')' in macro argument list");
|
||||
break;
|
||||
} else if (!is_identifier(l.constData(), l.length())) {
|
||||
qDebug() << l;
|
||||
error("Unexpected character in macro argument list.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1935,6 +1935,13 @@ void tst_Moc::warnings_data()
|
|||
<< 1
|
||||
<< QString("IGNORE_ALL_STDOUT")
|
||||
<< QString(":2: Error: Macro invoked with too few parameters for a use of '#'");
|
||||
|
||||
QTest::newRow("QTBUG-54609: crash on invalid input")
|
||||
<< QByteArray::fromBase64("EAkJCQkJbGFzcyBjbGFzcyBiYWkcV2kgTUEKcGYjZGVmaW5lIE1BKFEs/4D/FoQ=")
|
||||
<< QStringList()
|
||||
<< 1
|
||||
<< QString("IGNORE_ALL_STDOUT")
|
||||
<< QString(":-1: Error: Unexpected character in macro argument list.");
|
||||
}
|
||||
|
||||
void tst_Moc::warnings()
|
||||
|
|
@ -1950,7 +1957,7 @@ void tst_Moc::warnings()
|
|||
|
||||
#ifdef Q_CC_MSVC
|
||||
// for some reasons, moc compiled with MSVC uses a different output format
|
||||
QRegExp lineNumberRe(":(\\d+):");
|
||||
QRegExp lineNumberRe(":(-?\\d+):");
|
||||
lineNumberRe.setMinimal(true);
|
||||
expectedStdErr.replace(lineNumberRe, "(\\1):");
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue