All of lore.kernel.org
 help / color / mirror / Atom feed
* bug in parsing escaped characters in dquoted string
@ 2009-11-05  8:33 BVK
  2009-11-06 15:24 ` BVK
  0 siblings, 1 reply; 3+ messages in thread
From: BVK @ 2009-11-05  8:33 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

Hi,


Current parsers (rescue-mode and sh-mode) parses don't seem to handle
escape characters in double quoted strings like the way bash does.
For example, in bash

echo "\""

prints single double quote character with escape processing and

echo "\a"

prints two characters without escape processing.


But grub parsers are not handling the first case.  Attached patch
fixes this issue.



thanks,
-- 
bvk-chaitanya

[-- Attachment #2: escaped-dquote-in-dquote-string.patch --]
[-- Type: application/octet-stream, Size: 1906 bytes --]

Index: kern/parser.c
===================================================================
--- kern/parser.c	(revision 2682)
+++ kern/parser.c	(working copy)
@@ -39,7 +39,10 @@
 
   { GRUB_PARSER_STATE_DQUOTE, GRUB_PARSER_STATE_TEXT, '\"', 0},
   { GRUB_PARSER_STATE_DQUOTE, GRUB_PARSER_STATE_QVAR, '$', 0},
+  { GRUB_PARSER_STATE_DQUOTE, GRUB_PARSER_STATE_DQESC, '\\', 1},
 
+  { GRUB_PARSER_STATE_DQESC, GRUB_PARSER_STATE_DQUOTE, 0, 1},
+
   { GRUB_PARSER_STATE_VAR, GRUB_PARSER_STATE_VARNAME2, '{', 0},
   { GRUB_PARSER_STATE_VAR, GRUB_PARSER_STATE_VARNAME, 0, 1},
   { GRUB_PARSER_STATE_VARNAME, GRUB_PARSER_STATE_TEXT, ' ', 1},
@@ -182,6 +185,14 @@
 		      (*argc)++;
 		    }
 		}
+	      else if (state == GRUB_PARSER_STATE_DQESC
+		       && newstate == GRUB_PARSER_STATE_DQUOTE && use == '"')
+		{
+		  /* If escaped double quote in double quoted string
+		     is found, overwrite it on backslash character at
+		     top.  */
+		  *(bp - 1) = use;
+		}
 	      else if (use)
 		*(bp++) = use;
 	    }
Index: include/grub/parser.h
===================================================================
--- include/grub/parser.h	(revision 2682)
+++ include/grub/parser.h	(working copy)
@@ -29,6 +29,7 @@
   {
     GRUB_PARSER_STATE_TEXT = 1,
     GRUB_PARSER_STATE_ESC,
+    GRUB_PARSER_STATE_DQESC,
     GRUB_PARSER_STATE_QUOTE,
     GRUB_PARSER_STATE_DQUOTE,
     GRUB_PARSER_STATE_VAR,
Index: script/sh/lexer.c
===================================================================
--- script/sh/lexer.c	(revision 2682)
+++ script/sh/lexer.c	(working copy)
@@ -298,6 +298,13 @@
 		  if (breakout)
 		    break;
 		}
+	      /* If escaped double quote in double quoted string is
+		 found, remove backslash character from top.  */
+	      else if (newstate == GRUB_PARSER_STATE_DQUOTE
+		       && state->state == GRUB_PARSER_STATE_DQESC && use == '"')
+		{
+		  bufpos--;
+		}
 
 	      if (use)
 		{

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-06 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-05  8:33 bug in parsing escaped characters in dquoted string BVK
2009-11-06 15:24 ` BVK
2009-11-06 15:51   ` Vladimir 'phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.