#6792 segmentation fault (invalid code) in TemplateSimplifier::templateParameters. Avoid null pointer access

This commit is contained in:
Alexander Mai 2015-06-25 20:48:05 +02:00
parent ac1f0301c0
commit e75662aaf1
2 changed files with 9 additions and 0 deletions

View File

@ -292,6 +292,10 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
// Function pointer or prototype..
while (Token::Match(tok, "(|[")) {
if (!tok->link()) {
syntaxError(tok);
return 0;
}
tok = tok->link()->next();
while (Token::Match(tok, "const|volatile")) // Ticket #5786: Skip function cv-qualifiers
tok = tok->next();

View File

@ -131,6 +131,7 @@ private:
TEST_CASE(garbageCode89);
TEST_CASE(garbageCode90);
TEST_CASE(garbageCode91);
TEST_CASE(garbageCode92);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -717,6 +718,10 @@ private:
checkCode("typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] }"); // do not crash
}
void garbageCode92() { // #6792
ASSERT_THROW(checkCode("template < typename _Tp ( ( ) ; _Tp ) , decltype > { } { ( ) ( ) }"), InternalError); // do not crash
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"