|Anonymous | Login||2022-09-25 08:39 UTC|
|Main | My View | View Issues | Change Log | Docs|
|Viewing Issue Simple Details|
|ID||Category||Severity||Type||Date Submitted||Last Update|
|0001598||[1003.1(2016/18)/Issue7+TC2] System Interfaces||Editorial||Enhancement Request||2022-08-06 17:37||2022-08-08 09:04|
|Page Number||(page or range of pages)|
|Line Number||(Line or range of lines)|
|Final Accepted Text|
|Summary||0001598: putenv should be allowed to fail with EINVAL|
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
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:
musl libc does the same as GNU libc:
OpenBSD returns -1 and sets errno to EINVAL if the string does not contain
an '=' character:
FreeBSD is similar to OpenBSD but also generates EINVAL if the string is NULL,
or the '=' is the first character of the string:
NetBSD performs the same checks as FreeBSD:
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:
Solaris prior to Solaris 11.4.27 performed no checks on the string and would
never generate EINVAL:
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.)
Add to the 'The putenv() function may fail if:' list in the ERRORS section:
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'.
|Tags||No tags attached.|
The EINVAL error is already allowed courtesy of the general rules for additional errors (XSH 2.3). However, adding it is worth doing so that implementations can't choose a different error value instead of EINVAL for this condition. (Although the suggested wording is not quite right as it also covers, for example, a null pointer.)
More importantly, just adding the EINVAL error is not sufficient to allow the new Solaris behaviour (and Illumos, glibc and muslc). The first sentence of the putenv() description is `The putenv() function shall use the string argument to set environment variable values.' Notice the word set. This would not be a problem if it later said `The application shall ensure that the string argument points to a string of the form "name=value"', as the absence of an "=" would then be undefined behaviour, but because it only says `should', putenv() is required only to set, never unset, environment variables if it succeeds.
To allow putenv("name") to remove "name" from the environment, a more extensive rewording will be needed. I think it should explicitly only allow two behaviours (removing "name" or failing with EINVAL).
|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)|
|2022-08-08 09:02||geoffclare||Note Added: 0005926|
|2022-08-08 09:04||geoffclare||Project||1003.1(2013)/Issue7+TC1 => 1003.1(2016/18)/Issue7+TC2|
|Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group|