]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Fix endless loop in shell parser.
authorBruno Haible <bruno@clisp.org>
Sun, 18 Aug 2019 23:02:26 +0000 (01:02 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Apr 2020 11:06:10 +0000 (13:06 +0200)
Reported by Hanno Boeck at <https://savannah.gnu.org/bugs/?45408>.
Based on patch by Daiki Ueno.

* gettext-tools/src/x-sh.c (read_word): React on CLOSING_BACKQUOTE even when we
are currently not looking for a closing backquote.

gettext-tools/src/x-sh.c

index 79631f825ffa6cba659a3c32508fe7fdbc4081d9..0cf542efd35daa9fae62e01116edc457d3c27b37 100644 (file)
@@ -807,12 +807,29 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
         phase2_ungetc (c2);
     }
 
-  if (looking_for == CLOSING_BACKQUOTE && c == CLOSING_BACKQUOTE)
+  if (c == CLOSING_BACKQUOTE)
     {
-      saw_closing_backquote ();
-      wp->type = t_backquote;
-      last_non_comment_line = line_number;
-      return;
+      if (looking_for == CLOSING_BACKQUOTE)
+        {
+          saw_closing_backquote ();
+          wp->type = t_backquote;
+          last_non_comment_line = line_number;
+          return;
+        }
+      else if (looking_for == ')')
+        {
+          /* The input is invalid syntax, such as `a<(`
+             Push back the closing backquote and pretend that we have seen a
+             closing parenthesis.  */
+          phase2_ungetc (c);
+          wp->type = t_paren;
+          last_non_comment_line = line_number;
+          return;
+        }
+      else
+        /* We shouldn't be reading a CLOSING_BACKQUOTE when
+           looking_for == '\0'.  */
+        abort ();
     }
 
   if (looking_for == ')' && c == ')')