From nobody@FreeBSD.org  Wed Mar  7 02:04:34 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 1928E37B719
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  7 Mar 2001 02:04:32 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id f27A4WO41285;
	Wed, 7 Mar 2001 02:04:32 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200103071004.f27A4WO41285@freefall.freebsd.org>
Date: Wed, 7 Mar 2001 02:04:32 -0800 (PST)
From: wbriscoe@ponle.demon.co.uk
To: freebsd-gnats-submit@FreeBSD.org
Subject: sed.test 8.16 puts bugged sed into infinite loop
X-Send-Pr-Version: www-1.0

>Number:         25585
>Category:       misc
>Synopsis:       sed.test 8.16 puts bugged sed into infinite loop
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    dds
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 07 02:10:00 PST 2001
>Closed-Date:    Sat Aug 02 00:19:05 PDT 2003
>Last-Modified:  Sat Aug 02 05:28:33 PDT 2003
>Originator:     Walter Briscoe
>Release:        
>Organization:
P & O Nedlloyd
>Environment:
AIX iade05a2 1 4 000B0F90A400
GNU sed 3.02
>Description:
Test 8.16 in sed.test tests the ability of a sed to handle an empty
regular expression as the first argument to a substitute command. If
used to test a sed which (erroneously) evaluates this at translation
time rather than at execution time, the bugged sed is put into an
infinite loop. This mode of failure seems excessive. Such a failing
sed is the Free Software Foundation's sed 3.02.
I found this problem when I needed a test suite for the simtelnet MSDOS
port of sed. I was advised by Diomidis Spinellis - the copyright holder
of sed.test - that he no longer maintains it. The bug also exists in
OpenBsd and NetBSD. Please forward this pr or advise how I may submit
to those ports. http://www.freebsd.org/send-pr.html contains
"Note: copy/paste will destroy TABs and spacing, and this web form should not be used to submit code as plain text". It does not say what
should be used for that purpose. I hope the fix below is not mangled.
Should it be so, I hope somebody will come back to me to suggest
an improvement.

>How-To-Repeat:
Find a bugged sed - such as sed 3.02
Find the latest version (1.2) of sed.test from
http://www.freebsd.org/cgi/cvsweb.cg1/src/usr.bin/sed/TEST/sed.test
Run sed.test
test 8.16 does not complete.


>Fix:
The following solves the problem by limiting the number of iterations
of the infinite loop. There are probably more elegant ways of achieving
the same functionality.

09:43:26 05 /u/t150drs/freebsd: diff -C 3 sed.test.1.2 sed.test.new
*** sed.test.1.2        Wed Mar  7 09:27:05 2001
--- sed.test.new        Wed Mar  7 09:44:22 2001
***************
*** 504,511 ****
        if [ $BSD -eq 1 ] ; then
                echo 'BSD sed does not handle branch defined REs'
        else
                echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \
!                   -e 's//Y/p' -e '/f/bx'
        fi
  }

--- 504,521 ----
        if [ $BSD -eq 1 ] ; then
                echo 'BSD sed does not handle branch defined REs'
        else
+ #               The code below enters an infinite loop when testing
+ #               a sed which (wrongly) determines the meaning of the
+ #               empty RE in s//Y/p at compile time rather than run
+ #               time. w.briscoe@ponl.com 2001-03-07
+ #             echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \
+ #                 -e 's//Y/p' -e '/f/bx'
                echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \
!                   -e 's//Y/p' \
!                     -e x \
!                     -e /.\{10\}/{s/.*/ERROR/ -e b -e } -e s/.*/&./ \
!                     -e x \
!                     -e '/f/bx'
        fi
  }

09:43:29 05 /u/t150drs/freebsd:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dds 
Responsible-Changed-By: schweikh 
Responsible-Changed-When: Sat Jul 19 10:58:21 PDT 2003 
Responsible-Changed-Why:  
Diomidis, can you have a look at this? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25585 
State-Changed-From-To: open->patched 
State-Changed-By: dds 
State-Changed-When: Tue Jul 22 12:24:33 PDT 2003 
State-Changed-Why:  
Implemented the suggested change in a bit more readable manner. 
Change verified against a problematic FSF GNU sed and the (now working) 
FreeBSD sed. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=25585 
State-Changed-From-To: patched->closed 
State-Changed-By: dds 
State-Changed-When: Sat Aug 2 00:18:27 PDT 2003 
State-Changed-Why:  
Fix MFCed to RELENG_4 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25585 
>Unformatted:
