svn commit: r213284 - in head: tools/regression/usr.bin/tr usr.bin/tr

Jilles Tjoelker jilles at FreeBSD.org
Wed Sep 29 22:24:19 UTC 2010


Author: jilles
Date: Wed Sep 29 22:24:18 2010
New Revision: 213284
URL: http://svn.freebsd.org/changeset/base/213284

Log:
  tr: Fix '[=]=]' equivalence class.
  
  A closing bracket immediately after '[=' should not be treated as special.
  
  Different from the submitted patch, a string ending with '[=' does not cause
  access beyond the terminating '\0'.
  
  PR:		bin/150384
  Submitted by:	Richard Lowe
  MFC after:	2 weeks

Added:
  head/tools/regression/usr.bin/tr/regress.0c.out   (contents, props changed)
  head/tools/regression/usr.bin/tr/regress.0d.out   (contents, props changed)
Modified:
  head/tools/regression/usr.bin/tr/regress.sh
  head/usr.bin/tr/str.c

Added: head/tools/regression/usr.bin/tr/regress.0c.out
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/tr/regress.0c.out	Wed Sep 29 22:24:18 2010	(r213284)
@@ -0,0 +1 @@
+[[[[

Added: head/tools/regression/usr.bin/tr/regress.0d.out
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/tr/regress.0d.out	Wed Sep 29 22:24:18 2010	(r213284)
@@ -0,0 +1 @@
+

Modified: head/tools/regression/usr.bin/tr/regress.sh
==============================================================================
--- head/tools/regression/usr.bin/tr/regress.sh	Wed Sep 29 21:56:31 2010	(r213283)
+++ head/tools/regression/usr.bin/tr/regress.sh	Wed Sep 29 22:24:18 2010	(r213284)
@@ -1,6 +1,6 @@
 # $FreeBSD$
 
-echo 1..12
+echo 1..14
 
 REGRESSION_START($1)
 
@@ -16,5 +16,7 @@ REGRESSION_TEST(`08', `tr "[[:upper:]]" 
 REGRESSION_TEST(`09', `printf "\\f\\r\\n" | tr "\\014\\r" "?#"')
 REGRESSION_TEST(`0a', `printf "0xdeadbeef\\n" | tr "x[[:xdigit:]]" "?\$"')
 REGRESSION_TEST(`0b', `(tr -cd "[[:xdigit:]]" < regress2.in ; echo)')
+REGRESSION_TEST(`0c', `echo "[[[[]]]]" | tr -d "[=]=]"')
+REGRESSION_TEST(`0d', `echo "]=[" | tr -d "[=]"')
 
 REGRESSION_END()

Modified: head/usr.bin/tr/str.c
==============================================================================
--- head/usr.bin/tr/str.c	Wed Sep 29 21:56:31 2010	(r213283)
+++ head/usr.bin/tr/str.c	Wed Sep 29 22:24:18 2010	(r213284)
@@ -156,7 +156,7 @@ bracket(s)
 		s->str = p + 1;
 		return (1);
 	case '=':				/* "[=equiv=]" */
-		if ((p = strchr(s->str + 2, ']')) == NULL)
+		if (s->str[2] == '\0' || (p = strchr(s->str + 3, ']')) == NULL)
 			return (0);
 		if (*(p - 1) != '=' || p - s->str < 4)
 			goto repeat;


More information about the svn-src-head mailing list