Commit Graph

20 Commits

Author SHA1 Message Date
Roland McGrath 6cfae52edf Fix setenv.c diagnostic pragma to be compatible with GCC 4.6 2015-06-02 12:58:45 -07:00
Paul Eggert 03c1e456b0 Better fix for setenv (..., NULL, ...)
* stdlib/setenv.c (__add_to_environ):
Dump core quickly if setenv (..., NULL, ...) is called.
This time, do it the right way, and pacify GCC with a pragma.
2015-04-19 01:07:31 -07:00
Paul Eggert cb21929049 * stdlib/setenv.c (__add_to_environ): Revert previous change. 2015-03-15 17:06:21 -07:00
Paul Eggert 2ecccaede9 * stdlib/setenv.c (__add_to_environ):
Dump core quickly if setenv (..., NULL, ...) is called.
2015-03-13 10:14:03 -07:00
Eric Biggers d5b1c5ed8b setenv fix memory leak when setting large, duplicate string (BZ #17658)
glibc maintains a binary tree of environment strings it malloc()ed
itself.  However, it's possible for it to malloc() a string, then find
that an identical string is already in the tree.  In this case, the
memory is leaked and is not freed if the application later calls
__libc_freeres().  Fix this by freeing 'new_value' when it's unneeded.

Test case:
	#include <stdlib.h>
	#include <string.h>

	int main()
	{
		char *p = calloc(100000, 1);
		memset(p, 'A', 99999);
		setenv("TESTVAR", p, 1);
		setenv("TESTVAR", p, 1);
		free(p);
	}

Leak that was reported by valgrind:
	100,008 bytes in 1 blocks are definitely lost in loss record 1 of 1
	   at 0x4C29F90: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
	   by 0x4E6B3D4: __add_to_environ (setenv.c:176)
	   by 0x4C31B8F: setenv (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
	   by 0x400642: main (in /mnt/tmpfs/a.out)
2015-01-07 12:10:52 +05:30
Joseph Myers b168057aaa Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
Ondřej Bílka 83a3406e0f Remove unused variable from stdlib/setenv.c 2014-02-11 12:43:49 +01:00
Ondřej Bílka a1ffb40e32 Use glibc_likely instead __builtin_expect. 2014-02-10 15:07:12 +01:00
Ondřej Bílka 1448f32447 Fix previous commit. 2014-02-10 14:22:31 +01:00
Ondřej Bílka f3d338c9f3 Deduplicate setenv.
Setenv contained a code path that was redundant as it could be handled
in general case.
2014-02-10 12:54:10 +01:00
Allan McRae d4697bc93d Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
Joseph Myers 60d2f8f3c7 Use (void) in no-arguments function definitions. 2013-06-08 00:22:23 +00:00
Joseph Myers 2e09a79ada Avoid use of "register" as optimization hint. 2013-06-07 22:24:35 +00:00
Joseph Myers 568035b787 Update copyright notices with scripts/update-copyrights. 2013-01-02 19:05:09 +00:00
Paul Eggert 59ba27a63a Replace FSF snail mail address with URLs. 2012-02-09 23:18:22 +00:00
Ulrich Drepper c63bfa7994 Avoid alloca in setenv for long strings. 2010-02-02 09:55:55 -08:00
Ulrich Drepper 1fa7ae05b9 * stdlib/setenv.c (unsetenv): Don't search environment if it does
not exist.
2008-12-02 01:40:59 +00:00
Ulrich Drepper 9d13fb2413 Moved to csu/errno-loc.c. 2005-12-14 15:06:39 +00:00
Ulrich Drepper a334319f65 (CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4. 2004-12-22 20:10:10 +00:00
Jakub Jelinek 0ecb606cb6 2.5-18.1 2007-07-12 18:26:36 +00:00