Home | History | Annotate | Download | only in stdlib
History log of /src/lib/libc/stdlib/getenv.c
RevisionDateAuthorComments
 1.37  11-Feb-2022  rillig libc/getenv: remove trailing whitespace

No binary change.
 1.36  20-Jan-2015  christos Fix non _REENTRANT build.
 1.35  14-Nov-2010  tron 1.) Rename internal function __findvar() to __findenvvar().
2.) Add a wrapper function __findenv() which implements the previous
*internal* interface. It turns out that ld.elf_so(1) and pthread(3)
both use it.

Stripping e.g. "LD_LIBRARY_PATH" from the environment while running
setuid binaries works again now.
 1.34  14-Nov-2010  tron Set errno to ENOENT if we reject the environment variable name in
getenv_r() instead of leaving it unchanged.
 1.33  14-Nov-2010  tron Improve and simplify implementation of *env(3) functions:
- Use RB tree to keep track of memory allocated via setenv(3) as
suggested by Enami Tsugutomo in private e-mail.
This simplifies the code a lot as we no longer need to keep the size
of "environ" in sync with an array of allocated environment variables.
It also makes it possible to free environment variables in unsetenv(3)
if something has changed the order of the "environ" array.
- Fix a bug in getenv(3) and getenv_r(3) which would return bogus
results e.g. for " getenv("A=B") " if an environment variable "A"
with value "B=C" exists.
- Clean up the internal functions:
- Don't expose the read/write lock for the environment to other parts
of "libc". Provide locking functions instead.
- Use "bool" to report success or failure.
- Use "ssize_t" or "size_t" instead of "int" for indexes.
- Provide internal functions with simpler interfaces e.g. don't
combine return values and reference arguments.
- Don't copy "environ" into an allocated block unless we really need
to grow it.

Code reviewed by Joerg Sonnenberger and Christos Zoulas, tested by
Joerg Sonnenberger and me. These changes also fix problems in
zsh 4.3.* and pam_ssh according to Joerg.
 1.32  10-Nov-2010  enami Clear all entries past the NULL while scrubing environ vector.
 1.31  10-Nov-2010  enami Indent using tab rather than four spaces.
 1.30  04-Nov-2010  christos scrub the whole array, not just the first n malloced entries.
 1.29  03-Nov-2010  christos Handle the case where a program attempted to cleanup the environment by
setting *environ = NULL;
 1.28  02-Nov-2010  enami - Simplify the code
- Reword the comment.
 1.27  01-Nov-2010  enami Double the array only when really necessary. Otherwise memory will be
exhausted if user modifies the variable envrion itself repeatedly..
 1.26  24-Oct-2010  tron Double the size of the allocate environment vector when we resize it.
This should speed up extending the environment via setenv(3).
 1.25  02-Oct-2010  tron Make sure that all extra elements of the environment vector are set
to NULL. This stop su(1) from crashing.
 1.24  01-Oct-2010  christos make putenv POSIX compliant.
 1.23  29-Sep-2010  enami If new length is exactly equals to the current length,
there is nothing to do.
 1.22  25-Sep-2010  christos be more conservative about allocing.
 1.21  25-Sep-2010  tron Remember memory used by allocated environment variables instead of
using a bitmap. This deals with the case where a variable is first
set via setenv(3) or putenv(3), then overwritten by changing
"environ" directory and afterwards overwritten with setenv(3) again.

This stops "zsh" from crashing under NetBSD-current.

Code reviewed by Christos Zoulas.
 1.20  23-Sep-2010  christos Use a bit array to keep track of malloced environment entries so we can
free them.
 1.19  31-Oct-2008  christos branches: 1.19.2;
make __findenv return the offset for the new entry to be inserted when
the string is not found, to avoid an additional scan of the environ array
in setenv.
 1.18  25-Sep-2005  christos branches: 1.18.26;
add getenv_r and ttyname_r
 1.17  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.16  18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.15  19-Dec-2000  christos branches: 1.15.2;
fix nested extern declaration.
 1.14  20-Sep-1999  lukem back out the #ifdef _DIAGNOSTIC argument checks; too many people complained.
_DIAGASSERT() is still retained.
 1.13  16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.12  15-Nov-1998  christos delint
 1.11  11-Sep-1998  kleink Add a multiple-reader/single-writer lock to protect environ.
 1.10  03-Feb-1998  perry remove obsolete register declarations
 1.9  30-Jan-1998  perry update to lite-2
 1.8  13-Jul-1997  christos Add local.h for local prototypes.
Fix namespace issues for strtoq and strtouq
Fix gcc warnings.
Fix RCSID's
 1.7  20-Dec-1996  cgd const poisoning: __findenv()'s first arg should be const char * (lint)
 1.6  28-Dec-1995  thorpej New-style RCS ids.
 1.5  28-Feb-1995  jtc remove unneeded "#include <stddef.h>"
 1.4  15-Oct-1993  jtc branches: 1.4.4;
Rename _findenv() to __findenv(), as _findenv is in the user's namespace.
 1.3  26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2  01-Aug-1993  mycroft Add RCS identifiers.
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2  30-Jan-1998  perry import lite-2
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.4.1  02-May-1995  jtc #include "namespace.h"
 1.15.2.1  08-Aug-2001  nathanw _REENT -> _REENTRANT
 1.18.26.1  22-Nov-2010  riz Pull up following revision(s) (requested by tron in ticket #1474):
lib/libc/stdlib/getenv.c: revision 1.33 via patch
- Fix a bug in getenv(3) and getenv_r(3) which would return bogus
results e.g. for " getenv("A=3DB") " if an environment variable "A"
with value "B=3DC" exists.
 1.19.2.2  31-Oct-2008  christos make __findenv return the offset for the new entry to be inserted when
the string is not found, to avoid an additional scan of the environ array
in setenv.
 1.19.2.1  31-Oct-2008  christos file getenv.c was added on branch christos-time_t on 2008-10-31 17:46:05 +0000

RSS XML Feed