From owner-freebsd-bugs Wed Dec 27 23:30:03 1995 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id XAA19528 for bugs-outgoing; Wed, 27 Dec 1995 23:30:03 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id XAA19522 Wed, 27 Dec 1995 23:30:02 -0800 (PST) Date: Wed, 27 Dec 1995 23:30:02 -0800 (PST) Message-Id: <199512280730.XAA19522@freefall.freebsd.org> To: freebsd-bugs Cc: From: mark@linus.demon.co.uk (Mark Valentine) Subject: Re: bin/908: sed bug with trailing backslashes Reply-To: mark@linus.demon.co.uk (Mark Valentine) Sender: owner-bugs@FreeBSD.ORG Precedence: bulk The following reply was made to PR bin/908; it has been noted by GNATS. From: mark@linus.demon.co.uk (Mark Valentine) To: FreeBSD-gnats-submit@FreeBSD.ORG Cc: Subject: Re: bin/908: sed bug with trailing backslashes Date: Thu, 28 Dec 1995 07:19:57 +0000 > From: Mark Valentine > Date: Thu 21 Dec, 1995 > Subject: bin/908: sed bug with trailing backslashes > >Description: > > Sed misinterprets the pair of backslashes at the end of line 2 of > the following script, resulting in line 3 being taken as part of > the inserted text. > > 1i\ > char foo[] = "\\ > s/$/\\n\\/ > $a\ > "; This small patch to usr.bin/sed/compile.c seems to fix it. It replaces escaping backslashes in the input buffer with NULs, and uses those to determine whether the newline was escaped, rather than looking for a (possibly escaped) preceding backslash. --- compile.c.dist Wed Aug 16 21:21:55 1995 +++ compile.c Thu Dec 28 06:32:03 1995 @@ -628,11 +628,11 @@ EATSPACE(); for (; *p; p++) { if (*p == '\\') - p++; + *p++ = '\0'; *s++ = *p; } size += s - op; - if (p[-2] != '\\') { + if (p[-2] != '\0') { *s = '\0'; break; } This patch doesn't seem to break any of the regression tests. Mark.