]> granicus.if.org Git - clang/commitdiff
[lex] Don't create a garbage token if parsing of __has_include fails.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 29 Mar 2015 15:33:29 +0000 (15:33 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 29 Mar 2015 15:33:29 +0000 (15:33 +0000)
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

lib/Lex/PPMacroExpansion.cpp
test/Preprocessor/has_include.c

index 7763181549461b9b8e82b51d0c6adbff5387e973..f2baddd0b8349f70d7fb6703c093ac76dfee0ff3 100644 (file)
@@ -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.
index 131e51919f76d786482c96a4ac2ff24aefc998f4..ad7329390ef67b293c4129c9b1253a8ba3ea0b28 100644 (file)
@@ -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