From 51024996015ea25534be0b45c703e18cc97fceaa Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Tue, 7 Aug 2018 14:47:39 +0000 Subject: [PATCH] sed(1): partial fix for the case of the regex delimited with '['. We don't generally support the weird case of regular expresions delimited by an opening square bracket ('[') but POSIX says that inside bracket expressions, escaping is not possible and both '[' and '\' represent themselves. PR: 230198 (exp-run) Obtained from: OpenBSD --- usr.bin/sed/compile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c index 4427faeff4a2..df64a5c598c2 100644 --- a/usr.bin/sed/compile.c +++ b/usr.bin/sed/compile.c @@ -393,11 +393,11 @@ compile_delimited(char *p, char *d, int is_tr) if ((d = compile_ccl(&p, d)) == NULL) errx(1, "%lu: %s: unbalanced brackets ([])", linenum, fname); continue; + } else if (*p == '\\' && p[1] == c) { + p++; } else if (*p == '\\' && p[1] == '[') { *d++ = *p++; - } else if (*p == '\\' && p[1] == c) - p++; - else if (*p == '\\' && p[1] == 'n') { + } else if (*p == '\\' && p[1] == 'n') { *d++ = '\n'; p += 2; continue;