bug-gnu-utils
[Top][All Lists]
Advanced

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

sed: incorrect preparsing of non-matching bracket expressions


From: Eero Häkkinen
Subject: sed: incorrect preparsing of non-matching bracket expressions
Date: Sat, 23 Apr 2005 16:14:14 +0200
User-agent: KMail/1.7.2

The sed program parses incorrectly non-matching bracket expressions containing 
closing bracket then searching for the end of a regular expression. As a 
result, a command

  $ sed -n '/[^][]/p'
  sed: -e expression #1, char 8: unterminated address regex

does not work. Commands

  $ sed -n '/[][]/p'
  $ sed -n '/[^][[]/p'

do work.

The problem is that then searching for the end of a regular expression sed 
treats the closing bracket right after a circumflex as an end of a 
non-matching range while it should not i.e. a closing bracket in the very 
beginning of a range (after a possible initial circumflex) is not a special 
character in basic regular expressions (BRE) used by sed.

The bug is in function snarf_char_class and can be corrected by this patch:

--- sed/compile.c.orig  2005-04-19 10:37:21.791715104 +0200
+++ sed/compile.c       2005-04-19 10:37:47.070872088 +0200
@@ -463,7 +463,7 @@
   ch = inchar();
   if (ch == '^')
     ch = add_then_next(b, ch);
-  else if (ch == CLOSE_BRACKET)
+  if (ch == CLOSE_BRACKET)
     ch = add_then_next(b, ch);

   /* States are:




reply via email to

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