aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@openbsd.org>2015-07-20 00:54:01 +0000
committerTed Unangst <tedu@openbsd.org>2015-07-20 00:54:01 +0000
commit8cd9e5e59f39760e91b8a8413b4ec753954d5b6c (patch)
tree088b5f6aa9a06a6e589bba5edf6fd1df919c9a94
parentf5e3a415df7177b7b3a26464341ade4337a1c0b2 (diff)
downloadopendoas-8cd9e5e59f39760e91b8a8413b4ec753954d5b6c.tar.gz
introduce a minimal badset ($ENV) for environment stripping so that
root shells read the right .kshrc
-rw-r--r--doas.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/doas.c b/doas.c
index 8db988e..50dbccb 100644
--- a/doas.c
+++ b/doas.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: doas.c,v 1.9 2015/07/18 18:44:26 tedu Exp $ */
+/* $OpenBSD: doas.c,v 1.10 2015/07/19 01:19:22 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;
}