]> git.armaanb.net Git - opendoas.git/blobdiff - env.c
Handle empty argv
[opendoas.git] / env.c
diff --git a/env.c b/env.c
index f1fe45fbc83a6f51c7a2448209abe42b48f044f0..e2286fc83b0232425f67a8cda355ef1453f7739f 100644 (file)
--- a/env.c
+++ b/env.c
@@ -15,6 +15,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "config.h"
+
 #include <sys/types.h>
 #include "sys-tree.h"
 
 #include <errno.h>
 #include <pwd.h>
 
+#include "openbsd.h"
 #include "doas.h"
-#include "includes.h"
+
+const char *formerpath;
 
 struct envnode {
        RB_ENTRY(envnode) node;
@@ -199,10 +203,17 @@ fillenv(struct env *env, const char **envlist)
                /* assign value or inherit from environ */
                if (eq) {
                        val = eq + 1;
-                       if (*val == '$')
-                               val = getenv(val + 1);
+                       if (*val == '$') {
+                               if (strcmp(val + 1, "PATH") == 0)
+                                       val = formerpath;
+                               else
+                                       val = getenv(val + 1);
+                       }
                } else {
-                       val = getenv(name);
+                       if (strcmp(name, "PATH") == 0)
+                               val = formerpath;
+                       else
+                               val = getenv(name);
                }
                /* at last, we have something to insert */
                if (val) {