From darius@midget.dons.net.au  Mon Dec  5 23:51:19 2005
Return-Path: <darius@midget.dons.net.au>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B025216A423
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  5 Dec 2005 23:51:19 +0000 (GMT)
	(envelope-from darius@midget.dons.net.au)
Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E33FC43D66
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  5 Dec 2005 23:51:07 +0000 (GMT)
	(envelope-from darius@midget.dons.net.au)
Received: from midget.dons.net.au (ppp137-51.lns2.adl2.internode.on.net [59.167.137.51])
	by smtp1.adl2.internode.on.net (8.12.9/8.12.6) with ESMTP id jB5NovsU085321
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 6 Dec 2005 10:20:59 +1030 (CST)
	(envelope-from darius@midget.dons.net.au)
Received: from midget.dons.net.au (localhost [127.0.0.1])
	by midget.dons.net.au (8.13.4/8.13.3) with ESMTP id jB5Notxx016046
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 6 Dec 2005 10:20:56 +1030 (CST)
	(envelope-from darius@midget.dons.net.au)
Received: (from darius@localhost)
	by midget.dons.net.au (8.13.4/8.13.3/Submit) id jB5Nosxo016045;
	Tue, 6 Dec 2005 10:20:54 +1030 (CST)
	(envelope-from darius)
Message-Id: <200512052350.jB5Nosxo016045@midget.dons.net.au>
Date: Tue, 6 Dec 2005 10:20:54 +1030 (CST)
From: "Daniel J. O'Connor" <darius@dons.net.au>
Reply-To: "Daniel J. O'Connor" <darius@dons.net.au>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: env spins chewing CPU in some circumstances
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         90002
>Category:       bin
>Synopsis:       env spins chewing CPU in some circumstances
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gad
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 06 00:00:18 GMT 2005
>Closed-Date:    Mon Dec 12 02:30:56 GMT 2005
>Last-Modified:  Mon Dec 12 02:30:56 GMT 2005
>Originator:     Daniel J. O'Connor
>Release:        FreeBSD 6.0-RELEASE amd64
>Organization:
>Environment:
FreeBSD cain.gsoft.com.au 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Wed Nov  2 19:07:38 UTC 2005     root@rat.samsco.home:/usr/obj/usr/src/sys/GENERIC  amd64


>Description:
The env program has some regressions in 6.0 when used as a script interpreter. In some cases it will
spin in a tight loop consuming CPU.

>How-To-Repeat:
[cain 10:15] ~ >cat ./testscript
#!/usr/bin/env FOO=BAR /bin/sh

echo FOO in $FOO

In 6.0 amd64, and -current i386 it exhibits the failure above. In i386 5.4
it works. I believe it is a problem with 6.0 onwards and not architecture
specific but I don't have enough test machines to be sure.

It appears to be going in a strange loop allocating and freeing memory as
the size fluctuates between 1.2Mb and 380kb.

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->gad 
Responsible-Changed-By: gad 
Responsible-Changed-When: Thu Dec 8 23:38:34 GMT 2005 
Responsible-Changed-Why:  
I will look into this.  I expect it is a side-effect of the changes 
to #!-processing or the changes to /bin/env which were done for 
release 6.0.  I expect it is the parsing changes to #!-lines (in 
shell scripts) much more than /bin/env, because all of the 6.0 
changes to /bin/env were MFC'ed into 5.x-stable a long time ago. 

Besides that, the change to #!-line parsing is known to be an 
incompatible change.  That's why it was never MFC'ed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90002 
State-Changed-From-To: open->closed 
State-Changed-By: gad 
State-Changed-When: Mon Dec 12 02:24:43 UTC 2005 
State-Changed-Why:  
While this is an incompatible change in release 6.x, it is a known 
side-effect of a change that was agreed to after some discussion on 
freebsd-arch in February of 2005.  Look for the thread with a subject 
of "Bug in #! processing - One More Time". 

This change was made to fix some other issues with the parsing of 
parmaeters on #!-lines in shell scripts, and to make FreeBSD parse 
#!-lines the same way every other OS (including NetBSD and OpenBSD) 
parses them.  If you try your sample script on a Solaris box, for 
instance, you will run into the exact same infinite loop. 

If a user wants to get the same behavior which used to be the default 
in FreeBSD, they can do that by using the new '-S' option in the `env' 
command.  Please check `man env' for more details, and some examples. 

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