[9357] in Athena Bugs

home help back first fref pref prev next nref lref last post

rt 7.3P: BSD 4.3 setenv() trashes environ when out of memory

daemon@ATHENA.MIT.EDU (Barr3y Jaspan)
Sun May 24 21:58:05 1992

To: bugs@Athena.MIT.EDU
Date: Sun, 24 May 92 21:57:53 EDT
From: "Barr3y Jaspan" <bjaspan@Athena.MIT.EDU>

System name:		bill-the-cat
Type and version:	RTPC-ROMPC 7.3P (1 update(s) to same version)
Display type:		apa16

What's wrong:

The standard BSD 4.3 setenv() function sets the global variable
"environ" to NULL when there is not enough memory to store the new
environment variable.  Here's the code
(bsd-4.3/common/lib/libc/gen/setenv.c):

	environ = (char **)realloc((char *)environ,
	    (u_int)(sizeof(char *) * (cnt + 2)));
	if (!environ)
		return(-1);

What should have happened:

environ's value should not be changed if an out-of-memory error
occurs.  Possible bugs in realloc() do not justify this additional
lossage.

Please describe any relevant documentation references:
	setenv(2)

home help back first fref pref prev next nref lref last post