mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 14:25:15 +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:
26
env.c
26
env.c
@@ -250,23 +250,27 @@ setenv(var, val, overwrite)
|
|||||||
int overwrite;
|
int overwrite;
|
||||||
{
|
{
|
||||||
char *estring;
|
char *estring;
|
||||||
|
const char *varend;
|
||||||
size_t esize;
|
size_t esize;
|
||||||
|
int len;
|
||||||
|
|
||||||
if (strchr(var, '=') != NULL) {
|
/*
|
||||||
errno = EINVAL;
|
* POSIX says a var name with '=' is an error but BSD
|
||||||
return(-1);
|
* 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);
|
estring = emalloc(esize);
|
||||||
|
|
||||||
/* Build environment string and insert it. */
|
len = snprintf(estring, esize, "%.*s=%s", (int)(varend - var), var, val);
|
||||||
if (strlcpy(estring, var, esize) >= esize ||
|
if (len < 0 && len >= esize)
|
||||||
strlcat(estring, "=", esize) >= esize ||
|
|
||||||
strlcat(estring, val, esize) >= esize) {
|
|
||||||
|
|
||||||
errorx(1, "internal error, setenv() overflow");
|
errorx(1, "internal error, setenv() overflow");
|
||||||
}
|
|
||||||
/* Sync env.envp with environ as needed. */
|
/* Sync env.envp with environ as needed. */
|
||||||
if (env.envp != environ) {
|
if (env.envp != environ) {
|
||||||
char **ep;
|
char **ep;
|
||||||
|
Reference in New Issue
Block a user