mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-30 05:48:18 +00:00
setenv(3) in Linux treats a NUL value as the empty string
setenv(3) in BSD doesn't return an error if the name has '=' in it, it just treats the '=' as end of string.
This commit is contained in:
parent
182711e341
commit
c0c7180bba
26
env.c
26
env.c
@ -250,23 +250,27 @@ setenv(var, val, overwrite)
|
||||
int overwrite;
|
||||
{
|
||||
char *estring;
|
||||
const char *varend;
|
||||
size_t esize;
|
||||
int len;
|
||||
|
||||
if (strchr(var, '=') != NULL) {
|
||||
errno = EINVAL;
|
||||
return(-1);
|
||||
}
|
||||
/*
|
||||
* POSIX says a var name with '=' is an error but BSD
|
||||
* just ignores the '=' and anything after it.
|
||||
*/
|
||||
for (varend = var; *varend && *varend != '='; varend++)
|
||||
;
|
||||
|
||||
esize = strlen(var) + 1 + strlen(val) + 1;
|
||||
if (val == NULL)
|
||||
val = ""; /* glibc treats a NULL val as "" */
|
||||
|
||||
esize = (size_t)(varend - var) + 1 + strlen(val) + 1;
|
||||
estring = emalloc(esize);
|
||||
|
||||
/* Build environment string and insert it. */
|
||||
if (strlcpy(estring, var, esize) >= esize ||
|
||||
strlcat(estring, "=", esize) >= esize ||
|
||||
strlcat(estring, val, esize) >= esize) {
|
||||
|
||||
len = snprintf(estring, esize, "%.*s=%s", (int)(varend - var), var, val);
|
||||
if (len < 0 && len >= esize)
|
||||
errorx(1, "internal error, setenv() overflow");
|
||||
}
|
||||
|
||||
/* Sync env.envp with environ as needed. */
|
||||
if (env.envp != environ) {
|
||||
char **ep;
|
||||
|
Loading…
x
Reference in New Issue
Block a user