]> granicus.if.org Git - sudo/commitdiff
Make sudo_goodpath() return value boolean
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 10 Feb 2012 19:56:41 +0000 (14:56 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 10 Feb 2012 19:56:41 +0000 (14:56 -0500)
--HG--
branch : 1.7

find_path.c
goodpath.c
sudo.h

index fb7fb5f86cb23f88935fabc9328a1438144899cd..7881d2a66615d57ea7dbf4f306c76e0d444404ad 100644 (file)
@@ -63,8 +63,8 @@ find_path(infile, outfile, sbp, path, ignore_dot)
     static char command[PATH_MAX]; /* qualified filename */
     char *n;                   /* for traversing path */
     char *origpath;            /* so we can free path later */
-    char *result = NULL;       /* result of path/file lookup */
-    int checkdot = 0;          /* check current dir? */
+    int found = FALSE;         /* did we find the command? */
+    int checkdot = FALSE;      /* check current dir? */
     int len;                   /* length parameter */
 
     if (strlen(infile) >= PATH_MAX)
@@ -108,7 +108,7 @@ find_path(infile, outfile, sbp, path, ignore_dot)
        len = snprintf(command, sizeof(command), "%s/%s", path, infile);
        if (len <= 0 || len >= sizeof(command))
            errorx(1, "%s: File name too long", infile);
-       if ((result = sudo_goodpath(command, sbp)))
+       if ((found = sudo_goodpath(command, sbp)))
            break;
 
        path = n + 1;
@@ -119,17 +119,17 @@ find_path(infile, outfile, sbp, path, ignore_dot)
     /*
      * Check current dir if dot was in the PATH
      */
-    if (!result && checkdot) {
+    if (!found && checkdot) {
        len = snprintf(command, sizeof(command), "./%s", infile);
        if (len <= 0 || len >= sizeof(command))
            errorx(1, "%s: File name too long", infile);
-       result = sudo_goodpath(command, sbp);
-       if (result && ignore_dot)
+       found = sudo_goodpath(command, sbp);
+       if (found && ignore_dot)
            return NOT_FOUND_DOT;
     }
 
-    if (result) {
-       *outfile = result;
+    if (found) {
+       *outfile = command;
        return FOUND;
     } else
        return NOT_FOUND;
index 45066d3c66f569191c1a35e45d251592dd589606..6b7af38c0f09188c2767ce029215edb49ae4c450 100644 (file)
 /*
  * Verify that path is a normal file and executable by root.
  */
-char *
+int
 sudo_goodpath(path, sbp)
     const char *path;
     struct stat *sbp;
 {
     struct stat sb;
-
-    /* Check for brain damage */
-    if (path == NULL || path[0] == '\0')
-       return NULL;
-
-    if (stat(path, &sb))
-       return NULL;
-
-    /* Make sure path describes an executable regular file. */
-    if (!S_ISREG(sb.st_mode) || !(sb.st_mode & 0000111)) {
-       errno = EACCES;
-       return NULL;
+    int rval = FALSE;
+
+    if (path != NULL && stat(path, &sb) == 0) {
+       /* Make sure path describes an executable regular file. */
+       if (S_ISREG(sb.st_mode) && ISSET(sb.st_mode, 0111))
+           rval = TRUE;
+       else
+           errno = EACCES;
+       if (sbp)
+           (void) memcpy(sbp, &sb, sizeof(struct stat));
     }
 
-    if (sbp != NULL)
-       (void) memcpy(sbp, &sb, sizeof(struct stat));
-    return (char *)path;
+    return rval;
 }
diff --git a/sudo.h b/sudo.h
index 36edf22cb48c8810c429fcad231c54a8e796987c..19eaeba1decf6aadc0d3cc924c295f228216373d 100644 (file)
--- a/sudo.h
+++ b/sudo.h
@@ -253,7 +253,7 @@ char *sudo_getepw   __P((const struct passwd *));
 int gettime            __P((struct timeval *));
 
 /* goodpath.c */
-char *sudo_goodpath    __P((const char *, struct stat *));
+int sudo_goodpath      __P((const char *, struct stat *));
 
 /* gram.y */
 int yyparse            __P((void));