more scripting fixes
PATCH 1/1 more scripting fixes
Hello. I discovered that the lines like
echo \"hello\"
and
echo "a
b"
weren't parsed correctly.
Here is a fix. I have tested it throughly yet
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
ChangeLog +8 -0
@@ -1,3 +1,11 @@ +2009-06-10 Vladimir Serbinenko <[email protected]> + + Fix handling of string like \"hello\" and "a + b" + + * script/sh/lexer.c (check_textstate): accept GRUB_PARSER_STATE_ESC + (grub_script_yylex): fix parsing of quoting, escaping and newline + 2009-06-09 Michel Hermier <[email protected]> * fs/i386/pc/pxe.c (grub_pxefs_read): Fix returned values.
script/sh/lexer.c +20 -7
@@ -39,6 +39,7 @@ static int check_textstate (grub_parser_state_t state) {return (state ==GRUB_PARSER_STATE_TEXT + || state ==GRUB_PARSER_STATE_ESC || state ==GRUB_PARSER_STATE_QUOTE || state ==GRUB_PARSER_STATE_DQUOTE ); }
@@ -155,18 +156,20 @@ grub_script_yylex (union YYSTYPE *yylval, struct grub_parser_param *parsestate)return token; } -for (;! state->done && (*state->script || firstrun); firstrun =0 ) +for (;! state->done; firstrun =0 ) {if (! *state->script) {/* Check if more tokens are requested by the parser. */ if (((state->refs && ! parsestate->err) - || state->state ==GRUB_PARSER_STATE_ESC ) + || state->state ==GRUB_PARSER_STATE_ESC + || state->state ==GRUB_PARSER_STATE_QUOTE + || state->state ==GRUB_PARSER_STATE_DQUOTE ) && state->getline) {int doexit =0 ; -while (!state->script || !grub_strlen (state->script)) +while (! state->script || ! *state->script) {grub_free (state->newscript); state->newscript =0 ;
@@ -182,11 +185,18 @@ grub_script_yylex (union YYSTYPE *yylval, struct grub_parser_param *parsestate)break ;grub_dprintf ("scripting" ,"token=`\\n'\n" );recordchar (state,'\n' ); -if (state->state !=GRUB_PARSER_STATE_ESC ) +if (state->state !=GRUB_PARSER_STATE_ESC + && state->state !=GRUB_PARSER_STATE_DQUOTE + && state->state !=GRUB_PARSER_STATE_QUOTE ) { state->tokenonhold ='\n' ;break ; } +if (state->state ==GRUB_PARSER_STATE_DQUOTE + || state->state ==GRUB_PARSER_STATE_QUOTE ) + yylval->arg =grub_script_arg_add (parsestate, yylval->arg, +GRUB_SCRIPT_ARG_TYPE_STR , +"\n" ); }else {
@@ -199,8 +209,9 @@ grub_script_yylex (union YYSTYPE *yylval, struct grub_parser_param *parsestate) } } - newstate =grub_parser_cmdline_state (state->state, *state->script, &use); - + newstate =grub_parser_cmdline_state (state->state, *state->script, + &use); +/* Check if it is a text. */ if (check_textstate (newstate)) {
@@ -270,7 +281,9 @@ grub_script_yylex (union YYSTYPE *yylval, struct grub_parser_param *parsestate)when a special token was found. It will be recognized next time when this function is called. */ if (newstate ==GRUB_PARSER_STATE_TEXT - && state->state !=GRUB_PARSER_STATE_ESC ) + && state->state !=GRUB_PARSER_STATE_ESC + && state->state !=GRUB_PARSER_STATE_QUOTE + && state->state !=GRUB_PARSER_STATE_DQUOTE ) {int breakout =0 ;
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
(quoted diff) +4
-0+ Fix handling of string like \"hello\" and "a + b" + + * script/sh/lexer.c (check_textstate): accept
GRUB_PARSER_STATE_ESC
+ (grub_script_yylex): fix parsing of quoting, escaping and
newline
I needed to tweak the patch and remove a trivial chunk from it to make it apply to the current sources. The adjusted patch is attached. ChangeLog entries should not be part of the patch.
I confirm that the patch doesn't introduce any compiler warnings. The patch does fix what it claims to fix.
But something is still wrong:
grub:sh > echo "a\"b""
a\b
grub:sh > echo "a\"b''c
a\bc
It looks like \" cancels quoting for the subsequent characters, but it shouldn't.
Signature · 2 lines
Regards, Pavel Roskin
Fix handling of strings like \"hello\" and newlines in strings
From: Vladimir 'phcoder' Serbinenko <[email protected]>
ChangeLog:
* script/sh/lexer.c (check_textstate): accept GRUB_PARSER_STATE_ESC (grub_script_yylex): fix parsing of quoting, escaping and newline
---
script/sh/lexer.c | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-)
script/sh/lexer.c +17 -5
@@ -39,6 +39,7 @@ static int check_textstate (grub_parser_state_t state) {return (state ==GRUB_PARSER_STATE_TEXT + || state ==GRUB_PARSER_STATE_ESC || state ==GRUB_PARSER_STATE_QUOTE || state ==GRUB_PARSER_STATE_DQUOTE ); }
@@ -155,18 +156,20 @@ grub_script_yylex (union YYSTYPE *yylval, struct grub_parser_param *parsestate)return token; } -for (;! state->done && (*state->script || firstrun); firstrun =0 ) +for (;! state->done; firstrun =0 ) {if (! *state->script) {/* Check if more tokens are requested by the parser. */ if (((state->refs && ! parsestate->err) - || state->state ==GRUB_PARSER_STATE_ESC ) + || state->state ==GRUB_PARSER_STATE_ESC + || state->state ==GRUB_PARSER_STATE_QUOTE + || state->state ==GRUB_PARSER_STATE_DQUOTE ) && state->getline) {int doexit =0 ; -while (!state->script || !grub_strlen (state->script)) +while (! state->script || ! *state->script) {grub_free (state->newscript); state->newscript =0 ;
@@ -182,11 +185,18 @@ grub_script_yylex (union YYSTYPE *yylval, struct grub_parser_param *parsestate)break ;grub_dprintf ("scripting" ,"token=`\\n'\n" );recordchar (state,'\n' ); -if (state->state !=GRUB_PARSER_STATE_ESC ) +if (state->state !=GRUB_PARSER_STATE_ESC + && state->state !=GRUB_PARSER_STATE_DQUOTE + && state->state !=GRUB_PARSER_STATE_QUOTE ) { state->tokenonhold ='\n' ;break ; } +if (state->state ==GRUB_PARSER_STATE_DQUOTE + || state->state ==GRUB_PARSER_STATE_QUOTE ) + yylval->arg =grub_script_arg_add (parsestate, yylval->arg, +GRUB_SCRIPT_ARG_TYPE_STR , +"\n" ); }else {
@@ -270,7 +280,9 @@ grub_script_yylex (union YYSTYPE *yylval, struct grub_parser_param *parsestate)when a special token was found. It will be recognized next time when this function is called. */ if (newstate ==GRUB_PARSER_STATE_TEXT - && state->state !=GRUB_PARSER_STATE_ESC ) + && state->state !=GRUB_PARSER_STATE_ESC + && state->state !=GRUB_PARSER_STATE_QUOTE + && state->state !=GRUB_PARSER_STATE_DQUOTE ) {int breakout =0 ;
Quoted 9 lines · Pavel Roskin
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
+ Fix handling of string like \"hello\" and "a
+ b"
+
+ *script/sh/lexer.c(check_textstate): acceptGRUB_PARSER_STATE_ESC
+ (grub_script_yylex): fix parsing of quoting, escaping and newline
Quoted 3 lines
I needed to tweak the patch and remove a trivial chunk from it to make it apply to the current sources. The adjusted patch is attached. ChangeLog entries should not be part of the patch.
Thank you for rediff but it wasn't really necessary. As for changelog I don't see for it creates problems for anyone since I commit my patches myself and for testing this reject doesn't hurt anyway
Quoted 9 lines
But something is still wrong:
grub:sh > echo "a\"b""
a\b
grub:sh > echo "a\"b''c
a\bcIt looks like \" cancels quoting for the subsequent characters, but it shouldn't.
Actually the problem is different: escaping in quoting isn't parsed at all. For first step lexer uses rescue mode parser which isn't that easy to extend compactly. I think that we should leave rescue mode parser as it is now and put a better first-step parser in sh.mod. I'll do it when my todo list scrols to this point
Quoted 11 lines
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines
It looks like \" cancels quoting for the subsequent characters, but it shouldn't.
Actually the problem is different: escaping in quoting isn't parsed at all. For first step lexer uses rescue mode parser which isn't that easy to extend compactly. I think that we should leave rescue mode parser as it is now and put a better first-step parser in sh.mod. I'll do it when my todo list scrols to this point
I see.
I have no objections against your patch, but it would be better if you split it into logical pieces. Parsing is hard to get right and easy to break, and we don't have a testsuite to catch breakage.
Some changes are trivial, such as replacing
while (!state->script || ! grub_strlen (state->script))
with
while (! state->script || ! *state->script)
Other changes actually change the behavior. If you can split the fix for escaped quotes from the fix for quoted newlines, it would be good. This way, if any breakage is found, it could be traced to a smaller change.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 10 lines · Pavel Roskin
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines
It looks like \" cancels quoting for the subsequent characters, but it shouldn't.
Actually the problem is different: escaping in quoting isn't parsed at all. For first step lexer uses rescue mode parser which isn't that easy to extend compactly. I think that we should leave rescue mode parser as it is now and put a better first-step parser in sh.mod. I'll do it when my todo list scrols to this point
Quoted 5 lines
I see.
I have no objections against your patch, but it would be better if you split it into logical pieces. Parsing is hard to get right and easy to break, and we don't have a testsuite to catch breakage.
Good idea will do it when comitting
Quoted 24 lines
Some changes are trivial, such as replacing
while (!state->script || !
grub_strlen(state->script))with
while (!
state->script|| !*state->script)Other changes actually change the behavior. If you can split the fix for escaped quotes from the fix for quoted newlines, it would be good. This way, if any breakage is found, it could be traced to a smaller change.
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Comitted
Quoted 48 lines · Vladimir 'phcoder' Serbinenko
Quoted 10 lines · Pavel Roskin
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines
It looks like \" cancels quoting for the subsequent characters, but it shouldn't.
Actually the problem is different: escaping in quoting isn't parsed at all. For first step lexer uses rescue mode parser which isn't that easy to extend compactly. I think that we should leave rescue mode parser as it is now and put a better first-step parser in sh.mod. I'll do it when my todo list scrols to this point
Quoted 5 lines
I see.
I have no objections against your patch, but it would be better if you split it into logical pieces. Parsing is hard to get right and easy to break, and we don't have a testsuite to catch breakage.
Good idea will do it when comitting
Quoted 19 lines
Some changes are trivial, such as replacing
while (!state->script || !
grub_strlen(state->script))with
while (!
state->script|| !*state->script)Other changes actually change the behavior. If you can split the fix for escaped quotes from the fix for quoted newlines, it would be good. This way, if any breakage is found, it could be traced to a smaller change.
--
Regards,
Pavel RoskinQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Regards
Vladimir 'phcoder' Serbinenko
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko