]> git.armaanb.net Git - opendoas.git/blobdiff - doas.c
Merge doas.c 1.34 from OpenBSD CVS.
[opendoas.git] / doas.c
diff --git a/doas.c b/doas.c
index eda11b3e78e209a3def747aba410332f79f481c5..f0cbab295bfb265cc4c03f9bf2e4077c0e68d293 100644 (file)
--- a/doas.c
+++ b/doas.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: doas.c,v 1.32 2015/07/29 00:00:31 tedu Exp $ */
+/* $OpenBSD: doas.c,v 1.33 2015/07/30 17:04:33 tedu Exp $ */
 /*
  * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
  *
@@ -45,9 +45,11 @@ arraylen(const char **arr)
 {
        size_t cnt = 0;
 
-       while (*arr) {
-               cnt++;
-               arr++;
+       if (arr) {
+               while (*arr) {
+                       cnt++;
+                       arr++;
+               }
        }
        return cnt;
 }
@@ -162,10 +164,7 @@ parseconfig(const char *filename, int checkperms)
 
        yyfp = fopen(filename, "r");
        if (!yyfp) {
-               if (checkperms)
-                       fprintf(stderr, "doas is not enabled.\n");
-               else
-                       warn("could not open config file");
+               warn("could not open config file");
                exit(1);
        }
 
@@ -188,10 +187,10 @@ parseconfig(const char *filename, int checkperms)
  * Copy the environment variables in safeset from oldenvp to envp.
  */
 static int
-copyenvhelper(const char **oldenvp, const char **safeset, int nsafe,
+copyenvhelper(const char **oldenvp, const char **safeset, size_t nsafe,
     char **envp, int ei)
 {
-       int i;
+       size_t i;
 
        for (i = 0; i < nsafe; i++) {
                const char **oe = oldenvp;
@@ -224,8 +223,8 @@ copyenv(const char **oldenvp, struct rule *rule)
        char **envp;
        const char **extra;
        int ei;
-       int nsafe, nbad;
-       int nextras = 0;
+       size_t nsafe, nbad;
+       size_t nextras = 0;
 
        /* if there was no envvar whitelist, pass all except badset ones */
        nbad = arraylen(badset);
@@ -333,6 +332,7 @@ main(int argc, char **argv, char **envp)
        int nflag = 0;
 
        uid = getuid();
+
        while ((ch = getopt(argc, argv, "C:nsu:")) != -1) {
                switch (ch) {
                case 'C':
@@ -362,7 +362,6 @@ main(int argc, char **argv, char **envp)
        } else if ((!sflag && !argc) || (sflag && argc))
                usage();
 
-       uid = getuid();
        pw = getpwuid(uid);
        if (!pw)
                err(1, "getpwuid failed");