diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-03-29 15:33:29 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-03-29 15:33:29 +0000 |
commit | 18ff02dd5139d153b027564a5e43c554b08dcc39 (patch) | |
tree | b25f057b6bba2291288bc21ef8f71b054286db33 /clang | |
parent | 3012e59bc7a7224f59a8356feed54ac57b0bedb4 (diff) | |
download | bcm5719-llvm-18ff02dd5139d153b027564a5e43c554b08dcc39.tar.gz bcm5719-llvm-18ff02dd5139d153b027564a5e43c554b08dcc39.zip |
[lex] Don't create a garbage token if parsing of __has_include fails.
It will crash downstream somewhere. Found by afl-fuzz.
llvm-svn: 233493
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 6 | ||||
-rw-r--r-- | clang/test/Preprocessor/has_include.c | 12 |
2 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 77631815494..f2baddd0b83 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/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/clang/test/Preprocessor/has_include.c b/clang/test/Preprocessor/has_include.c index 131e51919f7..ad7329390ef 100644 --- a/clang/test/Preprocessor/has_include.c +++ b/clang/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 <FILENAME>}} +#if __has_include('x' +#endif + +// expected-error@+1 {{expected "FILENAME" or <FILENAME}} expected-error@+1 {{expected end of line in preprocessor expression}} +#if __has_include('x') +#endif + // expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}} // expected-note@+1 {{to match this '('}} #if __has_include(<stdint.h> #endif |