bison-patches
[Top][All Lists]
Advanced

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

[PATCH 8/8] be sure to properly escape type names


From: Akim Demaille
Subject: [PATCH 8/8] be sure to properly escape type names
Date: Thu, 26 Jul 2012 12:44:22 +0200

* src/scan-code.l: Use obstack_quote when passing type_name to m4.
* tests/input.at (Code injection): New.
* NEWS: Document it.
Thanks to Paul Eggert for the wording.
---
 NEWS            |  5 +++++
 src/scan-code.l | 12 +++++++-----
 tests/input.at  | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 53ae964..f4decfa 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU Bison NEWS
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+ Bison no longer executes user-specified M4 code when processing a grammar.
+
+** Bug fixes
+
+  Type names are now properly escaped.
 
 * Noteworthy changes in release 2.6 (2012-07-19) [stable]
 
diff --git a/src/scan-code.l b/src/scan-code.l
index 785f386..42d3ade 100644
--- a/src/scan-code.l
+++ b/src/scan-code.l
@@ -765,8 +765,9 @@ handle_action_dollar (symbol_list *rule, char *text, 
location dollar_loc)
           type_name = "";
         }
 
-      obstack_fgrow1 (&obstack_for_string,
-                     "]b4_lhs_value([%s])[", type_name);
+      obstack_sgrow (&obstack_for_string, "]b4_lhs_value(");
+      obstack_quote (&obstack_for_string, type_name);
+      obstack_sgrow (&obstack_for_string, ")[");
       rule->action_props.is_value_used = true;
       break;
 
@@ -786,9 +787,10 @@ handle_action_dollar (symbol_list *rule, char *text, 
location dollar_loc)
           type_name = "";
         }
 
-      obstack_fgrow3 (&obstack_for_string,
-                     "]b4_rhs_value(%d, %d, [%s])[",
-                     effective_rule_length, n, type_name);
+      obstack_fgrow2 (&obstack_for_string,
+                     "]b4_rhs_value(%d, %d, ", effective_rule_length, n);
+      obstack_quote (&obstack_for_string, type_name);
+      obstack_sgrow (&obstack_for_string, ")[");
       if (n > 0)
        symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
          true;
diff --git a/tests/input.at b/tests/input.at
index 836ff6d..eb98cca 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -1369,3 +1369,54 @@ AT_TEST([%define api.prefix foo], [-p bar], 
[input.y:1.9-18])
 m4_popdef([AT_TEST])
 
 AT_CLEANUP
+
+
+## ---------------- ##
+## Code injection.  ##
+## ---------------- ##
+
+
+AT_SETUP([[Code injection]])
+
+m4_pattern_allow([^m4_errprintn$])
+
+# AT_TEST([MACRO])
+# ----------------
+# Try to have MACRO be run by bison.
+m4_pushdef([AT_TEST],
+[AT_DATA([[input.y]],
+[[%type <$1(DEAD %type)> exp
+%token <$1(DEAD %token)> a
+%initial-action
+{
+  $$;
+  $<$1(DEAD %initial-action)>$
+};
+%%
+exp:
+  a a[last]
+  {
+    $$;
+    $][1;
+    $<$1(DEAD action 1)>$
+    $<$1(DEAD action 2)>1
+    $<$1(DEAD action 3)>last
+    $<$1(DEAD action 4)>0
+    ;
+  };
+]])
+
+# FIXME: Provide a means to iterate over all the skeletons.
+AT_BISON_CHECK([[-d               input.y]])
+AT_BISON_CHECK([[-d -S glr.c      input.y]])
+AT_BISON_CHECK([[-d -S lalr1.cc   input.y]])
+AT_BISON_CHECK([[-d -S glr.cc     input.y]])
+AT_BISON_CHECK([[   -S lalr1.java input.y]])
+])
+
+AT_TEST([m4_errprintn])
+AT_TEST([@:>@m4_errprintn])
+
+m4_popdef([AT_TEST])
+
+AT_CLEANUP
-- 
1.7.11.3




reply via email to

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