r233493 - [lex] Don't create a garbage token if parsing of __has_include fails.

Benjamin Kramer benny.kra at googlemail.com
Sun Mar 29 08:33:30 PDT 2015


Author: d0k
Date: Sun Mar 29 10:33:29 2015
New Revision: 233493

URL: http://llvm.org/viewvc/llvm-project?rev=233493&view=rev
Log:
[lex] Don't create a garbage token if parsing of __has_include fails.

It will crash downstream somewhere. Found by afl-fuzz.

Modified:
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/test/Preprocessor/has_include.c

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=233493&r1=233492&r2=233493&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sun Mar 29 10:33:29 2015
@@ -1461,9 +1461,11 @@ void Preprocessor::ExpandBuiltinMacro(To
       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.

Modified: cfe/trunk/test/Preprocessor/has_include.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_include.c?rev=233493&r1=233492&r2=233493&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/has_include.c (original)
+++ cfe/trunk/test/Preprocessor/has_include.c Sun Mar 29 10:33:29 2015
@@ -163,6 +163,18 @@ __has_include
 #if __has_include
 #endif
 
+// expected-error at +1 {{missing '(' after '__has_include'}}
+#if __has_include'x'
+#endif
+
+// expected-error at +1 {{expected "FILENAME" or <FILENAME>}}
+#if __has_include('x'
+#endif
+
+// expected-error at +1 {{expected "FILENAME" or <FILENAME}} expected-error at +1 {{expected end of line in preprocessor expression}}
+#if __has_include('x')
+#endif
+
 // expected-error at +1 {{missing ')' after '__has_include'}}  // expected-error at +1 {{expected value in expression}}  // expected-note at +1 {{to match this '('}}
 #if __has_include(<stdint.h>
 #endif





More information about the cfe-commits mailing list