Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Dec 1995 23:30:02 -0800 (PST)
From:      mark@linus.demon.co.uk (Mark Valentine)
To:        freebsd-bugs
Subject:   Re: bin/908: sed bug with trailing backslashes
Message-ID:  <199512280730.XAA19522@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199512280730.XAA19522>