summaryrefslogtreecommitdiff
path: root/usr.bin/doas
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-07-20 00:54:02 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-07-20 00:54:02 +0000
commit3385be8aad996489324ee6ca14629dd58811716a (patch)
treeffda7f16f61c3d07c7f11c695717e9c6afd5de3e /usr.bin/doas
parentf4a38503b7c5fb2a10bd3df62bb1dafd14e9751e (diff)
introduce a minimal badset ($ENV) for environment stripping so that
root shells read the right .kshrc
Diffstat (limited to 'usr.bin/doas')
-rw-r--r--usr.bin/doas/doas.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/usr.bin/doas/doas.c b/usr.bin/doas/doas.c
index 23074b4322a..ef78c223263 100644
--- a/usr.bin/doas/doas.c
+++ b/usr.bin/doas/doas.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: doas.c,v 1.10 2015/07/19 01:19:22 tedu Exp $ */
+/* $OpenBSD: doas.c,v 1.11 2015/07/20 00:54:01 tedu Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
@@ -190,25 +190,39 @@ copyenv(const char **oldenvp, struct rule *rule)
const char *safeset[] = {
"DISPLAY", "HOME", "LOGNAME", "MAIL", "SHELL",
"PATH", "TERM", "USER", "USERNAME",
- NULL,
+ NULL
+ };
+ const char *badset[] = {
+ "ENV",
+ NULL
};
char **envp;
const char **extra;
int ei;
- int i, j;
- int nsafe;
+ int i, ii, j, jj;
+ int nsafe, nbad;
int nextras = 0;
+ nbad = arraylen(badset);
if ((rule->options & KEEPENV) && !rule->envlist) {
j = arraylen(oldenvp);
envp = reallocarray(NULL, j + 1, sizeof(char *));
if (!envp)
err(1, "reallocarray");
- for (i = 0; i < j; i++) {
- if (!(envp[i] = strdup(oldenvp[i])))
- err(1, "strdup");
+ for (ii = i = 0; i < j; i++) {
+ for (jj = 0; jj < nbad; jj++) {
+ size_t len = strlen(badset[jj]);
+ if (strncmp(oldenvp[i], badset[jj], len) == 0) {
+ break;
+ }
+ }
+ if (jj == nbad) {
+ if (!(envp[ii] = strdup(oldenvp[i])))
+ err(1, "strdup");
+ ii++;
+ }
}
- envp[i] = NULL;
+ envp[ii] = NULL;
return envp;
}