From: Benjamin Kramer Date: Sun, 29 Mar 2015 15:33:29 +0000 (+0000) Subject: [lex] Don't create a garbage token if parsing of __has_include fails. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28954c618f9b6c6cf5e8c8a3ba212c83912b326d;p=clang [lex] Don't create a garbage token if parsing of __has_include fails. It will crash downstream somewhere. Found by afl-fuzz. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233493 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 7763181549..f2baddd0b8 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -1461,9 +1461,11 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { Value = EvaluateHasInclude(Tok, II, *this); else Value = EvaluateHasIncludeNext(Tok, II, *this); + + if (Tok.isNot(tok::r_paren)) + return; OS << (int)Value; - if (Tok.is(tok::r_paren)) - Tok.setKind(tok::numeric_constant); + Tok.setKind(tok::numeric_constant); } else if (II == Ident__has_warning) { // The argument should be a parenthesized string literal. // The argument to these builtins should be a parenthesized identifier. diff --git a/test/Preprocessor/has_include.c b/test/Preprocessor/has_include.c index 131e51919f..ad7329390e 100644 --- a/test/Preprocessor/has_include.c +++ b/test/Preprocessor/has_include.c @@ -163,6 +163,18 @@ __has_include #if __has_include #endif +// expected-error@+1 {{missing '(' after '__has_include'}} +#if __has_include'x' +#endif + +// expected-error@+1 {{expected "FILENAME" or }} +#if __has_include('x' +#endif + +// expected-error@+1 {{expected "FILENAME" or #endif