From 232a0ff51d29fcdbfc2a835309d92284931098dc Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Sat, 15 Jun 2002 07:38:27 +0000 Subject: [PATCH] Improve parsing of character and equivalence classes: [:*] and [=*] are parsed as `infinitely many repetitions of :' (or *) instead of literal characters (SUSv3) --- usr.bin/tr/str.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/usr.bin/tr/str.c b/usr.bin/tr/str.c index 1df43dcc655..7f5df8f2899 100644 --- a/usr.bin/tr/str.c +++ b/usr.bin/tr/str.c @@ -125,20 +125,25 @@ bracket(s) switch (s->str[1]) { case ':': /* "[:class:]" */ - if ((p = strstr(s->str + 2, ":]")) == NULL) + if ((p = strchr(s->str + 2, ']')) == NULL) return (0); - *p = '\0'; + if (*(p - 1) != ':' || p - s->str < 4) + goto repeat; + *(p - 1) = '\0'; s->str += 2; genclass(s); - s->str = p + 2; + s->str = p + 1; return (1); case '=': /* "[=equiv=]" */ - if ((p = strstr(s->str + 2, "=]")) == NULL) + if ((p = strchr(s->str + 2, ']')) == NULL) return (0); + if (*(p - 1) != '=' || p - s->str < 4) + goto repeat; s->str += 2; genequiv(s); return (1); default: /* "[\###*n]" or "[#*n]" */ + repeat: if ((p = strpbrk(s->str + 2, "*]")) == NULL) return (0); if (p[0] != '*' || index(p, ']') == NULL)