]> git.armaanb.net Git - opendoas.git/commitdiff
introduce a minimal badset ($ENV) for environment stripping so that
authorTed Unangst <tedu@openbsd.org>
Mon, 20 Jul 2015 00:54:01 +0000 (00:54 +0000)
committerTed Unangst <tedu@openbsd.org>
Mon, 20 Jul 2015 00:54:01 +0000 (00:54 +0000)
root shells read the right .kshrc

doas.c

diff --git a/doas.c b/doas.c
index 8db988ea242885ab834c4f9b3575b4de6dfc0ff4..50dbccbf9129906ef7e7adb47c666b8f72cab045 100644 (file)
--- 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;
        }