summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/getenv.c
Commit message (Collapse)AuthorAgeFilesLines
* libc: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-251-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326193
* Minor libc cleanup: let calloc(3) do the multiplication.Pedro F. Giffuni2017-03-131-1/+1
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=315187
* libc: provide some bounds-checking through reallocarray(3).Pedro F. Giffuni2017-03-121-4/+4
| | | | | | | | | | | | reallocarray(3) is a non portable extension that originated in OpenBSD. Given that it is already in FreeBSD's libc it is useful for the cases where reallocation involves a multiplication. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D9955 Notes: svn path=/head/; revision=315162
* [fix to r253380] __setenv: be explicit about placing '=' after nameAndriy Gapon2013-07-171-2/+1
| | | | | | | | | | | | | This should a regression introduced in r253380 if malloc'ed memory happens to have '=' at the right place. Reported by: ache Pointyhat to: me (avg) MFC after: 1 day X-MFC with: r253380 Notes: svn path=/head/; revision=253413
* libc: name passed into __setenv is not necessarily NUL-terminatedAndriy Gapon2013-07-161-1/+1
| | | | | | | | | That's particularly true when __setenv is called from __merge_environ. MFC after: 4 days Notes: svn path=/head/; revision=253380
* Optimize prev. commit for speed.Andrey A. Chernov2012-10-031-3/+7
| | | | | | | | | | | | 1) Don't iterate the loop from the environment array beginning each time, iterate it under the last place we deactivate instead. 2) Call __rebuild_environ() not on each iteration but once, only at the end of whole loop (of course, only in case if something is changed). MFC after: 1 week Notes: svn path=/head/; revision=241154
* Using putenv() and later direct pointer contents modification it is possibeAndrey A. Chernov2012-10-021-1/+3
| | | | | | | | | | | | | | | to craft environment variables with similar names like that: a=1 a=2 ... unsetenv("a") should remove them all to make later getenv("a") impossible. Fix it to do so (this is GNU autoconf test #3 failure too). PR: 172273 MFC after: 1 week Notes: svn path=/head/; revision=241137
* Revert behavior change to setenv(), unsetenv() and putenv() until a moreSean Farley2009-12-071-3/+6
| | | | | | | thorough security review has been completed. Notes: svn path=/head/; revision=200198
* Change the behavior of setenv(), putenv() and unsetenv() to continue parsingSean Farley2009-12-061-6/+3
| | | | | | | | | | | | | | | instead of returning an error if a corrupt (not a "name=value" string) entry in the environ array is detected when (re)-building the internal environment. This should prevent applications or libraries from experiencing issues arising from the expectation that these calls will complete even with corrupt entries. The behavior is now as it was prior to 7.0. Reviewed by: jilles MFC after: 1 week Notes: svn path=/head/; revision=200191
* Improve the comment within getenv() explaining the search order it takes toSean Farley2009-12-061-8/+9
| | | | | | | | | | | | | find a variable. Include a note that it must not cause the internal environment to be generated since malloc() depends upon getenv(). To call malloc() would create a circular dependency. Recommended by: green Approved by: jilles MFC after: 1 week Notes: svn path=/head/; revision=200190
* Temporarily revert the previous change because the linker has beenBrian Feldman2009-12-011-36/+28
| | | | | | | modified so that it will abort when the environment is bad. Notes: svn path=/head/; revision=199987
* Do not gratuitously fail *env(3) operations due to corrupt ('='-less)Brian Feldman2009-12-011-28/+36
| | | | | | | | | | | | | | | | **environ entries. This puts non-getenv(3) operations in line with getenv(3) in that bad environ entries do not cause all operations to fail. There is still some inconsistency in that getenv(3) in the absence of any environment-modifying operation does not emit corrupt environ entry warnings. I also fixed another inconsistency in getenv(3) where updating the global environ pointer would not be reflected in the return values. It would have taken an intermediary setenv(3)/putenv(3)/unsetenv(3) in order to see the change. Notes: svn path=/head/; revision=199983
* Restructure and use different variables in the tests that involveSean Farley2008-08-031-13/+15
| | | | | | | | | | | | environ[0] to be more obvious that environ is not NULL before environ[0] is tested. Although I believe the previous code worked, this change improves code maintainability. Reviewed by: ache MFC after: 3 days Notes: svn path=/head/; revision=181266
* Detect if the application has cleared the environ variable by settingSean Farley2008-08-021-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | the first value (environ[0]) to NULL. This is in addition to the current detection of environ being replaced, which includes being set to NULL. Without this fix, the environment is not truly wiped, but appears to be by getenv() until an *env() call is made to alter the enviroment. This change is necessary to support those applications that use this method for clearing environ such as Dovecot and Postfix. Applications such as Sendmail and the base system's env replace environ (already detected). While neither of these methods are defined by SUSv3, it is best to support them due to historic reasons and in lieu of a clean, defined method. Add extra units tests for clearing environ using four different methods: 1. Set environ to NULL pointer. 2. Set environ[0] to NULL pointer. 3. Set environ to calloc()'d NULL-terminated array. 4. Set environ to static NULL-terminated array. Noticed by: Timo Sirainen MFC after: 3 days Notes: svn path=/head/; revision=181150
* Replace the use of warnx() with direct output to stderr using _write().Sean Farley2008-02-281-12/+36
| | | | | | | | | | | | | | | | | | | This reduces the size of a statically-linked binary by approximately 100KB in a trivial "return (0)" test application. readelf -S was used to verify that the .text section was reduced and that using strlen() saved a few more bytes over using sizeof(). Since the section of code is only called when environ is corrupt (program bug), I went with fewer bytes over fewer cycles. I made minor edits to the submitted patch to make the output resemble warnx(). Submitted by: kib bz Approved by: wes (mentor) MFC after: 5 days Notes: svn path=/head/; revision=176632
* The precision for a string argument in a call to warnx() needs to be castSean Farley2007-09-221-1/+2
| | | | | | | | | | | | to an int to remove the warning from using a size_t variable on 64-bit platforms. Submitted by: Xin LI <delphij@FreeBSD.org> Approved by: wes Approved by: re (kensmith) Notes: svn path=/head/; revision=172294
* Skip rebuilding environ in setenv() only upon reuse of an active variable;Sean Farley2007-09-151-2/+2
| | | | | | | | | | | | | | inactive variables should cause a rebuild of environ, otherwise, exec()'d processes will be missing a variable in environ that has been unset then set. Submitted by: Taku Yamamoto <taku@tackymt.homeip.net> Reviewed by: ache Approved by: wes (mentor) Approved by: re (kensmith) Notes: svn path=/head/; revision=172191
* Added environ-replacement detection. For programs that "clean" (i.e., su)Sean Farley2007-07-201-78/+163
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | or replace (i.e., zdump) the environment after a call to setenv(), putenv() or unsetenv() has been made, a few changes were made. - getenv() will return the value from the new environ array. - setenv() was split into two functions: __setenv() which is most of the previous setenv() without checks on the name and setenv() which contains the checks before calling __setenv(). - setenv(), putenv() and unsetenv() will unset all previous values and call __setenv() on all entries in the new environ array which in turn adds them to the end of the envVars array. Calling __setenv() instead of setenv() is done to avoid the temporary replacement of the '=' in a string with a NUL byte. Some strings may be read-only data. Added more regression checks for clearing the environment array. Replaced gettimeofday() with getrusage() in timing regression check for better accuracy. Fixed an off-by-one bug in __remove_putenv() in the use of memmove(). This went unnoticed due to the allocation of double the number of environ entries when building envVars. Fixed a few spelling mistakes in the comments. Reviewed by: ache Approved by: wes Approved by: re (kensmith) Notes: svn path=/head/; revision=171525
* Significantly reduce the memory leak as noted in BUGS section forSean Farley2007-07-041-59/+538
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | setenv(3) by tracking the size of the memory allocated instead of using strlen() on the current value. Convert all calls to POSIX from historic BSD API: - unsetenv returns an int. - putenv takes a char * instead of const char *. - putenv no longer makes a copy of the input string. - errno is set appropriately for POSIX. Exceptions involve bad environ variable and internal initialization code. These both set errno to EFAULT. Several patches to base utilities to handle the POSIX changes from Andrey Chernov's previous commit. A few I re-wrote to use setenv() instead of putenv(). New regression module for tools/regression/environ to test these functions. It also can be used to test the performance. Bump __FreeBSD_version to 700050 due to API change. PR: kern/99826 Approved by: wes Approved by: re (kensmith) Notes: svn path=/head/; revision=171195
* Back out all POSIXified *env() changes.Andrey A. Chernov2007-05-011-5/+2
| | | | | | | | | | | | Not because I admit they are technically wrong and not because of bug reports (I receive nothing). But because I surprisingly meets so strong opposition and resistance so lost any desire to continue that. Anyone who interested in POSIX can dig out what changes and how through cvs diffs. Notes: svn path=/head/; revision=169177
* Make putenv() fully conforms to Open Group specs Issue 6Andrey A. Chernov2007-04-301-2/+5
| | | | | | | | | | | | | | (also IEEE Std 1003.1-2001) The specs explicitly says that altering passed string should change the environment, i.e. putenv() directly puts its arg into environment (unlike setenv() which just copies it there). It means that putenv() can't be implemented via setenv() (like we have before) at all. Putenv() value lives (allows modifying) up to the next putenv() or setenv() call. Notes: svn path=/head/; revision=169138
* Make setenv, putenv, getenv and unsetenv conforming to Open Group specsAndrey A. Chernov2007-04-301-5/+5
| | | | | | | | | | | | Issue 6 (also IEEE Std 1003.1-2001) in following areas: args, return, errors. Putenv still needs rewriting because specs explicitly says that altering passed string later should change the environment (currently we copy the string so can't provide that). Notes: svn path=/head/; revision=169109
* Per Regents of the University of Calfornia letter, remove advertisingWarner Losh2007-01-091-4/+0
| | | | | | | | | clause. # If I've done so improperly on a file, please let me know. Notes: svn path=/head/; revision=165903
* Remove __P() usage.David E. O'Brien2002-03-211-1/+1
| | | | Notes: svn path=/head/; revision=92905
* Remove 'register' keyword.David E. O'Brien2002-03-211-4/+6
| | | | Notes: svn path=/head/; revision=92889
* Doubled the performance of getenv()/__findenv() by rewriting it to notDavid Greenman1995-10-171-20/+24
| | | | | | | use strncmp().. Notes: svn path=/head/; revision=11549
* BSD 4.4 Lite Lib SourcesRodney W. Grimes1994-05-271-0/+87
Notes: svn path=/cvs2svn/branches/unlabeled-1.1.1/; revision=1573