🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs.usg
Article #338

bug in SysV f77 library function getenv() and fix

#338
From: Daniel R. Levy
Date: Fri, 12 Sep 1986 21:58
70 lines
2197 bytes
There is a bug in the System V f77 library function getenv() which shows up
when the environment is not sorted (as when under ksh), and the environment
variable which is sought occurs in the environment list after another envir-
onment variable of which it is a prefix.

	Repeat-by:

C
C  bug.f
C
	character*20 envvar
	call getenv('AA',envvar)
	write(6,10)envvar
10	format(1x,'Environment variable "AA"=',a)
	stop
	end

$ sh	# use Bourne shell at first
$ f77 -o bug bug.f
bug.f:
    MAIN:
$ AA=aa
$ export AA
$ AAA=bb
$ export AAA
$ env	# note sorted environment
...
AA=aa
AAA=bb
...
$ bug
 Environment variable "AA"=aa                  
$ ksh	# now try it under Korn shell
$ env	# note unsorted environment
...
AAA=bb
AA=aa
...
$ bug
 Environment variable "AA"=                    

Fix:

In ye olde FORTRAN tradition, this fix involves adding a goto :-).

/usr/src/lib/libF77/getenv_.c:

	...

	if(*ep++ == '=')	/* copy right hand side */
		while( *ep && --vlen>=0 )
			*value++ = *ep++;

	else goto endloop;	/* BUG FIX: if prefix match only,
					continue the environment search */

	goto blank;

endloop: ;
	}

	...
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy
Technical Details
Message-ID: <1190@ttrdc.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!princeton!allegra!ulysses!burl!clyde!cbatt!ihnp4!cuae2!ltuxa!ttrdc!levy

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!princeton!allegra!ulysses!burl!clyde!cbatt!ihnp4!cuae2!ltuxa!ttrdc!levy
From: levy@ttrdc.UUCP (Daniel R. Levy)
Newsgroups: net.bugs.usg,net.lang.f77
Subject: bug in SysV f77 library function getenv() and fix
Message-ID: <1190@ttrdc.UUCP>
Date: Fri, 12-Sep-86 17:58:09 EDT
Article-I.D.: ttrdc.1190
Posted: Fri Sep 12 17:58:09 1986
Date-Received: Sat, 13-Sep-86 23:40:49 EDT
Organization: AT&T, Computer Systems Division, Skokie, IL
Lines: 70