diff options
author | Martijn van Duren <martijn@cvs.openbsd.org> | 2018-06-19 12:36:19 +0000 |
---|---|---|
committer | Martijn van Duren <martijn@cvs.openbsd.org> | 2018-06-19 12:36:19 +0000 |
commit | a175a801354e4e0d28551a9058a0c863119ec755 (patch) | |
tree | 8b4a20060a64e8b3e44f0219d24d23b74100251e | |
parent | 9461db4e963d9472a1c6997b4322f2420e8ec301 (diff) |
Revert previous, there were some unintended beviour changes.
-rw-r--r-- | bin/ed/re.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/bin/ed/re.c b/bin/ed/re.c index 413011da63f..c81a3ee0518 100644 --- a/bin/ed/re.c +++ b/bin/ed/re.c @@ -1,4 +1,4 @@ -/* $OpenBSD: re.c,v 1.18 2018/06/18 17:08:20 martijn Exp $ */ +/* $OpenBSD: re.c,v 1.19 2018/06/19 12:36:18 martijn Exp $ */ /* $NetBSD: re.c,v 1.14 1995/03/21 09:04:48 cgd Exp $ */ /* re.c: This file contains the regular expression interface routines for @@ -94,10 +94,16 @@ extract_pattern(int delimiter) char *nd; int len; - for (nd = ibufp; *nd != delimiter && *nd != '\n'; nd++) { + for (nd = ibufp; *nd != delimiter && *nd != '\n'; nd++) switch (*nd) { default: break; + case '[': + if ((nd = parse_char_class(++nd)) == NULL) { + seterrmsg("unbalanced brackets ([])"); + return NULL; + } + break; case '\\': if (*++nd == '\n') { seterrmsg("trailing backslash (\\)"); @@ -105,7 +111,6 @@ extract_pattern(int delimiter) } break; } - } len = nd - ibufp; REALLOC(lhbuf, lhbufsz, len + 1, NULL); memcpy(lhbuf, ibufp, len); @@ -113,3 +118,22 @@ extract_pattern(int delimiter) ibufp = nd; return (isbinary) ? NUL_TO_NEWLINE(lhbuf, len) : lhbuf; } + + +/* parse_char_class: expand a POSIX character class */ +static char * +parse_char_class(char *s) +{ + int c, d; + + if (*s == '^') + s++; + if (*s == ']') + s++; + for (; *s != ']' && *s != '\n'; s++) + if (*s == '[' && ((d = *(s+1)) == '.' || d == ':' || d == '=')) + for (s++, c = *++s; *s != ']' || c != d; s++) + if ((c = *s) == '\n') + return NULL; + return (*s == ']') ? s : NULL; +} |