]> granicus.if.org Git - sudo/commitdiff
fixed bug with non-executable tings of same name in path introduced by checkig errno
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 8 Sep 1993 15:39:08 +0000 (15:39 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 8 Sep 1993 15:39:08 +0000 (15:39 +0000)
after stat(2).

find_path.c

index c88ae80b0110c25bb7b8eb94d58d3df1733fdbf6..ec8567916ae595ff1bc1188d73bbebec7f55d0bf 100644 (file)
@@ -77,7 +77,8 @@ char *find_path(file)
     register char *n;                  /* for traversing path */
     char *path = NULL;                 /* contents of PATH env var */
     char fn[MAXPATHLEN+1];             /* filename (path + file) */
-    struct stat statbuf;               /* for stat() */
+    struct stat statbuf;               /* for stat(2) */
+    int statfailed;                    /* stat(2) return value */
     char *qualify();
 
     if (strlen(file) > MAXPATHLEN) {
@@ -105,9 +106,10 @@ char *find_path(file)
        strcat(fn, file);
 
        /* stat the file to make sure it exists and is executable */
-       if (!stat(fn, &statbuf) && (statbuf.st_mode & 0000111))
+       statfailed = stat(fn, &statbuf);
+       if (!statfailed && (statbuf.st_mode & 0000111))
            return (qualify(fn));
-       else if (errno == ENOENT || errno == ENOTDIR)
+       else if (!statfailed || errno == ENOENT || errno == ENOTDIR)
            path=n+1;
        else {
            perror("find_path:  stat");