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

* Re: bug in parsing escaped characters in dquoted string
  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
  0 siblings, 1 reply; 3+ messages in thread
From: BVK @ 2009-11-06 15:24 UTC (permalink / raw)
  To: The development of GRUB 2

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

New patch for the same, with missing ChangeLog entry added.



-- 
bvk.chaitanya

[-- Attachment #2: escaped-dquote-in-dquote-string.patch --]
[-- Type: application/octet-stream, Size: 2361 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_QESC, '\\', 1},
 
+  { GRUB_PARSER_STATE_QESC, 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_QESC
+		       && 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_QESC,
     GRUB_PARSER_STATE_QUOTE,
     GRUB_PARSER_STATE_DQUOTE,
     GRUB_PARSER_STATE_VAR,
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2682)
+++ ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2009-11-06  BVK Chaitanya  <bvk.groups@gmail.com>
+
+	* include/grub/parser.h: Fix escaped double quote parsing in
+	double quoted strings.
+	* kern/parser.c: Likewise.
+	* script/sh/lexer.c: Likewise.
+
 2009-11-04  Felix Zielcke  <fzielcke@z-51.de>
 
 	* configure.ac (AC_PREREQ): Bump to 2.59d.
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_QESC && use == '"')
+		{
+		  bufpos--;
+		}
 
 	      if (use)
 		{

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

* Re: bug in parsing escaped characters in dquoted string
  2009-11-06 15:24 ` BVK
@ 2009-11-06 15:51   ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 3+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-11-06 15:51 UTC (permalink / raw)
  To: The development of GRUB 2

BVK wrote:
> New patch for the same, with missing ChangeLog entry added.
>
>
>   
The patch affects rescue parser too, increases size critical parts and
breaks FSM structure. I'll probably rewrite some parts of normal parser
not to use rescue parser
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>   


-- 
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git 




^ 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.