about summary refs log tree commit diff
path: root/src/env/putenv.c
Commit message (Collapse)AuthorAgeFilesLines
* overhaul environment functionsAlexander Monakov2017-09-041-43/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rewrite environment access functions to slim down code, fix bugs and avoid invoking undefined behavior. * avoid using int-typed iterators where size_t would be correct; * use strncmp instead of memcmp consistently; * tighten prologues by invoking __strchrnul; * handle NULL environ. putenv: * handle "=value" input via unsetenv too (will return -1/EINVAL); * rewrite and simplify __putenv; fix the leak caused by failure to deallocate entry added by preceding setenv when called from putenv. setenv: * move management of libc-allocated entries to this translation unit, and use no-op weak symbols in putenv/unsetenv; unsetenv: * rewrite; this fixes UB caused by testing a free'd pointer against NULL on entry to subsequent loops. Not changed: Failure to extend allocation tracking array (previously __env_map, now env_alloced) is ignored rather than causing to report -1/ENOMEM to the caller; the worst-case consequence is leaking this allocation when it is removed or replaced in a subsequent environment access. Initially UB in unsetenv was reported by Alexander Cherepanov. Using a weak alias to avoid pulling in malloc via unsetenv was suggested by Rich Felker.
* env: avoid leaving dangling pointers in __env_mapAlexander Monakov2016-03-061-0/+1
| | | | | | This is the minimal fix for __putenv leaving a pointer to freed heap storage in __env_map array, which could later on lead to errors such as double-free.
* include cleanups: remove unused headers and add feature test macrosSzabolcs Nagy2013-12-121-2/+0
|
* as an extension, have putenv("VAR") behave as unsetenv("VAR")Rich Felker2012-10-211-5/+5
| | | | | | the behavior of putenv is left undefined if the argument does not contain an equal sign, but traditional implementations behave this way and gnulib replaces putenv if it doesn't do this.
* initial check-in, version 0.5.0 v0.5.0Rich Felker2011-02-121-0/+59