From 92ac370570776d9021d21e1f3ca43a127e981956 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 7 Oct 2003 07:32:57 +0000 Subject: [PATCH] Do not allow NUL bytes in string literals or character constants. --- ChangeLog | 7 +++++++ doc/bison.texinfo | 3 ++- src/scan-gram.l | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 14616925..446bafe5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-10-07 Paul Eggert + + * doc/bison.texinfo (Symbols): NUL bytes are not allowed in string + literals, unfortunately. + * src/scan-gram.l (): + Complain about NUL bytes in character constants or string literals. + 2003-10-05 Paul Eggert * NEWS: Don't document %no-default-prec, as it's still diff --git a/doc/bison.texinfo b/doc/bison.texinfo index c7e1b633..c1bff43c 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -2481,7 +2481,8 @@ does not enforce this convention, but if you depart from it, people who read your program will be confused. All the escape sequences used in string literals in C can be used in -Bison as well. However, unlike Standard C, trigraphs have no special +Bison as well, except that you must not use a null character within a +string literal. Also, unlike Standard C, trigraphs have no special meaning in Bison string literals, nor is backslash-newline allowed. A literal string token must contain two or more characters; for a token containing just one character, use a character token (see above). diff --git a/src/scan-gram.l b/src/scan-gram.l index 5cbacfc1..742d54e8 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -371,6 +371,7 @@ splice (\\[ \f\t\v]*\n)* return STRING; } + \0 complain_at (*loc, _("invalid null character")); .|\n STRING_GROW; <> unexpected_eof (token_start, "\""); BEGIN INITIAL; } @@ -397,6 +398,7 @@ splice (\\[ \f\t\v]*\n)* return ID; } + \0 complain_at (*loc, _("invalid null character")); .|\n STRING_GROW; <> unexpected_eof (token_start, "'"); BEGIN INITIAL; } @@ -412,6 +414,8 @@ splice (\\[ \f\t\v]*\n)* unsigned long c = strtoul (yytext + 1, 0, 8); if (UCHAR_MAX < c) complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext)); + else if (! c) + complain_at (*loc, _("invalid null character: %s"), quote (yytext)); else obstack_1grow (&obstack_for_string, c); } @@ -422,6 +426,8 @@ splice (\\[ \f\t\v]*\n)* c = strtoul (yytext + 2, 0, 16); if (UCHAR_MAX < c || get_errno ()) complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext)); + else if (! c) + complain_at (*loc, _("invalid null character: %s"), quote (yytext)); else obstack_1grow (&obstack_for_string, c); } @@ -441,6 +447,8 @@ splice (\\[ \f\t\v]*\n)* int c = convert_ucn_to_byte (yytext); if (c < 0) complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext)); + else if (! c) + complain_at (*loc, _("invalid null character: %s"), quote (yytext)); else obstack_1grow (&obstack_for_string, c); } -- 2.45.2