bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bison 3.7.1.1] bison: src/parse-gram.c:3262: unquote: Assertion `*c


From: Akim Demaille
Subject: Re: [bison 3.7.1.1] bison: src/parse-gram.c:3262: unquote: Assertion `*cp == '"'' failed.
Date: Sat, 8 Aug 2020 08:12:02 +0200

Hi,

> Le 3 août 2020 à 06:29, 송수환 <sshkeb96@snu.ac.kr> a écrit :
> 
> Hi, This is Agency for Defense Development (ADD).
> 
> We found bison: src/parse-gram.c:3262: unquote: Assertion `*cp == '"'' failed.

Thanks for the report.  I'm installing the appended patch.

What fuzzer do you use?

Cheers!

commit b801b7b670872b8a31d11b3683b4afc3e45a07f8
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sat Aug 8 07:36:34 2020 +0200

    fix: unterminated \-escape
    
    An assertion failed when the last character is a '\' and we're in a
    character or a string.
    Reported by Agency for Defense Development.
    https://lists.gnu.org/r/bug-bison/2020-08/msg00009.html
    
    * src/scan-gram.l: Catch unterminated escapes.
    * tests/input.at (Unexpected end of file): New.

diff --git a/src/scan-gram.l b/src/scan-gram.l
index f957f137..e10d68e2 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -567,6 +567,8 @@ eqopt    ({sp}=)?
               _("POSIX Yacc does not support string literals"));
     RETURN_VALUE (STRING, last_string);
   }
+  <<EOF>>   unexpected_eof (token_start, "\"");
+  "\n"      unexpected_newline (token_start, "\"");
 }
 
 <SC_ESCAPED_TSTRING>
@@ -580,13 +582,10 @@ eqopt    ({sp}=)?
               _("POSIX Yacc does not support string literals"));
     RETURN_VALUE (TSTRING, last_string);
   }
+  <<EOF>>   unexpected_eof (token_start, "\")");
+  "\n"      unexpected_newline (token_start, "\")");
 }
 
-<SC_ESCAPED_STRING,SC_ESCAPED_TSTRING>
-{
-  <<EOF>>   unexpected_eof (token_start, "\"");
-  "\n"      unexpected_newline (token_start, "\"");
-}
 
 
   /*----------------------------------------------------------.
@@ -692,6 +691,15 @@ eqopt    ({sp}=)?
               p);
     STRING_1GROW ('?');
   }
+
+  "\\"             {
+    // None of the other rules matched: the last character of this
+    // file is "\".  But Flex does not support "\\<<EOF>>".
+    unexpected_eof (token_start,
+                    YY_START == SC_ESCAPED_CHARACTER ? "?'"
+                    : YY_START == SC_ESCAPED_STRING ? "?\""
+                    : "?\")");
+  }
 }
 
   /*--------------------------------------------.
diff --git a/tests/input.at b/tests/input.at
index 915cfed6..cfa065ad 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -1395,11 +1395,6 @@ AT_CLEANUP
 AT_SETUP([Torturing the Scanner])
 
 AT_BISON_OPTION_PUSHDEFS
-AT_DATA([input.y], [])
-AT_BISON_CHECK([input.y], [1], [],
-[[input.y:1.1: error: unexpected end of file
-]])
-
 
 AT_DATA([input.y],
 [{}
@@ -2506,6 +2501,99 @@ input.y:5.19: error: invalid character after \-escape: 
\001
 AT_CLEANUP
 
 
+## ------------------------ ##
+## Unexpected end of file.  ##
+## ------------------------ ##
+
+AT_SETUP([[Unexpected end of file]])
+
+
+AT_DATA([input.y], [])
+AT_BISON_CHECK([-fcaret input.y], [1], [],
+[[input.y:1.1: error: unexpected end of file
+]])
+
+
+AT_DATA_NO_FINAL_EOL([char.y],
+[[%token FOO ']])
+
+AT_BISON_CHECK([-fcaret char.y], [1], [],
+[[char.y:1.12: error: missing "'" at end of file
+    1 | %token FOO '
+      |            ^
+char.y:1.12: error: empty character literal
+    1 | %token FOO '
+      |            ^
+]])
+
+
+AT_DATA_NO_FINAL_EOL([escape-in-char.y],
+[[%token FOO '\]])
+
+AT_BISON_CHECK([-fcaret escape-in-char.y], [1], [],
+[[escape-in-char.y:1.12-13: error: missing '?\'' at end of file
+    1 | %token FOO '\
+      |            ^~
+escape-in-char.y:1.14: error: unexpected end of file
+    1 | %token FOO '\
+      |              ^
+]])
+
+
+AT_DATA_NO_FINAL_EOL([string.y],
+[[%token FOO "]])
+
+AT_BISON_CHECK([-fcaret string.y], [1], [],
+[[string.y:1.12: error: missing '"' at end of file
+    1 | %token FOO "
+      |            ^
+string.y:1.13: error: unexpected end of file
+    1 | %token FOO "
+      |             ^
+]])
+
+
+AT_DATA_NO_FINAL_EOL([escape-in-string.y],
+[[%token FOO "\]])
+
+AT_BISON_CHECK([-fcaret escape-in-string.y], [1], [],
+[[escape-in-string.y:1.12-13: error: missing '?"' at end of file
+    1 | %token FOO "\
+      |            ^~
+escape-in-string.y:1.14: error: unexpected end of file
+    1 | %token FOO "\
+      |              ^
+]])
+
+
+AT_DATA_NO_FINAL_EOL([tstring.y],
+[[%token FOO _("]])
+
+AT_BISON_CHECK([-fcaret tstring.y], [1], [],
+[[tstring.y:1.12-14: error: missing '")' at end of file
+    1 | %token FOO _("
+      |            ^~~
+tstring.y:1.15: error: unexpected end of file
+    1 | %token FOO _("
+      |               ^
+]])
+
+
+AT_DATA_NO_FINAL_EOL([escape-in-tstring.y],
+[[%token FOO _("\]])
+
+AT_BISON_CHECK([-fcaret escape-in-tstring.y], [1], [],
+[[escape-in-tstring.y:1.12-15: error: missing '?")' at end of file
+    1 | %token FOO _("\
+      |            ^~~~
+escape-in-tstring.y:1.16: error: unexpected end of file
+    1 | %token FOO _("\
+      |                ^
+]])
+
+AT_CLEANUP
+
+
 ## ------------------------- ##
 ## LAC: Errors for %define.  ##
 ## ------------------------- ##




reply via email to

[Prev in Thread] Current Thread [Next in Thread]