The following issue has been SUBMITTED. ====================================================================== https://austingroupbugs.net/view.php?id=1598 ====================================================================== Reported By: alanc Assigned To: ====================================================================== Project: 1003.1(2013)/Issue7+TC1 Issue ID: 1598 Category: System Interfaces Type: Enhancement Request Severity: Editorial Priority: normal Status: New Name: Alan Coopersmith Organization: Oracle Solaris User Reference: Section: putenv Page Number: (page or range of pages) Line Number: (Line or range of lines) Interp Status: --- Final Accepted Text: ====================================================================== Date Submitted: 2022-08-06 17:37 UTC Last Modified: 2022-08-06 17:37 UTC ====================================================================== Summary: putenv should be allowed to fail with EINVAL Description: setenv() is required to fail and return EINVAL if "The envname argument points to an empty string or points to a string containing an '=' character." in order to keep the environment in the expected "name=value" format.
putenv() currently states 'The string argument should point to a string of the form " name= value ".' but does not state what happens if that is not true. Some implementations currently accept invalid values while others check and reject them. GNU libc has added an extension to accept strings without an '=' character as an alias to unsetenv(), but does not seem to check for empty strings or otherwise generate EINVAL errors: https://man7.org/linux/man-pages/man3/putenv.3.html https://sourceware.org/git/?p=glibc.git;a=blob;f=stdlib/putenv.c musl libc does the same as GNU libc: https://git.musl-libc.org/cgit/musl/tree/src/env/putenv.c?h=v1.2.3 OpenBSD returns -1 and sets errno to EINVAL if the string does not contain an '=' character: https://man.openbsd.org/putenv.3 https://github.com/openbsd/src/blob/master/lib/libc/stdlib/setenv.c FreeBSD is similar to OpenBSD but also generates EINVAL if the string is NULL, or the '=' is the first character of the string: https://www.freebsd.org/cgi/man.cgi?query=putenv&sektion=3&format=html https://cgit.freebsd.org/src/tree/lib/libc/stdlib/getenv.c?h=release/13.1.0#n614 NetBSD performs the same checks as FreeBSD: https://man.netbsd.org/putenv.3 https://github.com/NetBSD/src/blob/trunk/lib/libc/stdlib/putenv.c#L59-L63 https://github.com/NetBSD/src/blob/trunk/lib/libc/stdlib/_env.c#L123-L148 illumos only checks for the string containing an '=', and if not, follows GNU libc in passing it to unsetenv() and does not ever generate EINVAL: https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/gen/getenv.c#L337-L351 https://illumos.org/man/3C/putenv Solaris prior to Solaris 11.4.27 performed no checks on the string and would never generate EINVAL: https://docs.oracle.com/cd/E86824_01/html/E54766/putenv-3c.html This has changed in Solaris 11.4.27 and later, in which Solaris will return -1 and set errno to EINVAL if the string is empty or starts with '=', and pass the string to unsetenv() if the string has a variable name but no '='. (The man page changes documenting this are in process and not yet published.) Desired Action: Add to the 'The putenv() function may fail if:' list in the ERRORS section: [EINVAL] The string argument is not a pointer to a string of the form "name=value". Listing this as "may" fail instead of "must" fail maintains compatibility with all of the implementations discussed above, including those with the extension to unsetenv a name provided with no '=value'. ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 2022-08-06 17:37 alanc New Issue 2022-08-06 17:37 alanc Name => Alan Coopersmith 2022-08-06 17:37 alanc Organization => Oracle Solaris 2022-08-06 17:37 alanc Section => putenv 2022-08-06 17:37 alanc Page Number => (page or range of pages) 2022-08-06 17:37 alanc Line Number => (Line or range of lines) ======================================================================