Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Mar 2001 02:04:32 -0800 (PST)
From:      w.briscoe@ponl.com
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/25585: sed.test 8.16 puts bugged sed into infinite loop
Message-ID:  <200103071004.f27A4WO41285@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         25585
>Category:       misc
>Synopsis:       sed.test 8.16 puts bugged sed into infinite loop
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 07 02:10:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Walter Briscoe
>Release:        I am not
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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