From mark@linus.demon.co.uk  Thu Dec 21 16:58:03 1995
Received: from linus.demon.co.uk (linus.demon.co.uk [158.152.10.220])
          by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id QAA25017
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 21 Dec 1995 16:57:56 -0800 (PST)
Received: (from mark@localhost) by linus.demon.co.uk (8.7.3/8.7.3) id SAA03054; Thu, 21 Dec 1995 18:11:21 GMT
Message-Id: <199512211811.SAA03054@linus.demon.co.uk>
Date: Thu, 21 Dec 1995 18:11:21 GMT
From: Mark Valentine <mark@linus.demon.co.uk>
Reply-To: mark@linus.demon.co.uk
To: FreeBSD-gnats-submit@freebsd.org
Subject: sed bug with trailing backslashes
X-Send-Pr-Version: 3.2

>Number:         908
>Category:       bin
>Synopsis:       sed bug with trailing backslashes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 21 17:00:01 PST 1995
>Closed-Date:    Wed Jun 19 16:00:42 PDT 1996
>Last-Modified:  Wed Jun 19 16:01:05 PDT 1996
>Originator:     Mark Valentine
>Release:        FreeBSD 2.2-CURRENT i386
>Organization:
>Environment:

	n/a

>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\
	    ";

	GNU sed and SunOS 4.1.3 sed insert a single line ending with a
	backslash, and treat line three as a substition command.

>How-To-Repeat:

	$ echo test | sed -f <above-script>
	char foo[] = "\
	s/$/\n\/
	test
	";

	$ echo test | /usr/gnu/bin/sed -f <above-script>
	char foo[] = "\
	test\n\
	";

>Fix:
>Release-Note:
>Audit-Trail:

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 <mark@linus.demon.co.uk>
 > 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.
State-Changed-From-To: open->closed 
State-Changed-By: nate 
State-Changed-When: Wed Jun 19 16:00:42 PDT 1996 
State-Changed-Why:  
PR bin/908 can be closed now (fix verified by submitter). 


>Unformatted:
