bug in SysV f77 library function getenv() and fix
Daniel R. Levy
levy at ttrdc.UUCP
Sat Sep 13 07:58:09 AEST 1986
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
More information about the Net.bugs.usg
mailing list