summaryrefslogtreecommitdiff
path: root/usr.bin/sudo/env.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2009-06-21 14:48:43 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2009-06-21 14:48:43 +0000
commita3e9aa1c62bdd4c50b28eaf86e3d3b01ad4f5a99 (patch)
tree84b345fa3b1060d2d6458f21ac9544af7a79ff31 /usr.bin/sudo/env.c
parent345d95045cd5281f339a2de55c5d54ea5f25ef46 (diff)
Upgrade to sudo 1.7.2
Diffstat (limited to 'usr.bin/sudo/env.c')
-rw-r--r--usr.bin/sudo/env.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/usr.bin/sudo/env.c b/usr.bin/sudo/env.c
index 16b9e61a075..54b685dfa85 100644
--- a/usr.bin/sudo/env.c
+++ b/usr.bin/sudo/env.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2005, 2007-2008
+ * Copyright (c) 2000-2005, 2007-2009
* Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -49,7 +49,7 @@
#include "sudo.h"
#ifndef lint
-__unused static const char rcsid[] = "$Sudo: env.c,v 1.101 2009/03/11 23:01:10 millert Exp $";
+__unused static const char rcsid[] = "$Sudo: env.c,v 1.105 2009/06/15 13:10:01 millert Exp $";
#endif /* lint */
/*
@@ -249,24 +249,35 @@ setenv(var, val, overwrite)
const char *val;
int overwrite;
{
- char *estring;
+ char *estring, *ep;
+ const char *cp;
size_t esize;
- if (strchr(var, '=') != NULL) {
- errno = EINVAL;
- return(-1);
- }
-
- esize = strlen(var) + 1 + strlen(val) + 1;
- estring = emalloc(esize);
+ if (!var || *var == '\0')
+ return(EINVAL);
- /* Build environment string and insert it. */
- if (strlcpy(estring, var, esize) >= esize ||
- strlcat(estring, "=", esize) >= esize ||
- strlcat(estring, val, esize) >= esize) {
+ /*
+ * POSIX says a var name with '=' is an error but BSD
+ * just ignores the '=' and anything after it.
+ */
+ for (cp = var; *cp && *cp != '='; cp++)
+ ;
+ esize = (size_t)(cp - var) + 2;
+ if (val) {
+ esize += strlen(val); /* glibc treats a NULL val as "" */
+ }
- errorx(1, "internal error, setenv() overflow");
+ /* Allocate and fill in estring. */
+ estring = ep = emalloc(esize);
+ for (cp = var; *cp && *cp != '='; cp++)
+ *ep++ = *cp;
+ *ep++ = '=';
+ if (val) {
+ for (cp = val; *cp; cp++)
+ *ep++ = *cp;
}
+ *ep = '\0';
+
/* Sync env.envp with environ as needed. */
if (env.envp != environ) {
char **ep;