]> granicus.if.org Git - sudo/commitdiff
now handles decending below '/' correctly
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 5 Sep 1993 13:55:34 +0000 (13:55 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 5 Sep 1993 13:55:34 +0000 (13:55 +0000)
find_path.c

index 5ef36ff730f5ed258011934559acbe9b3ff3afad..c88ae80b0110c25bb7b8eb94d58d3df1733fdbf6 100644 (file)
@@ -107,7 +107,7 @@ char *find_path(file)
        /* stat the file to make sure it exists and is executable */
        if (!stat(fn, &statbuf) && (statbuf.st_mode & 0000111))
            return (qualify(fn));
-       else if (errno == ENOENT)
+       else if (errno == ENOENT || errno == ENOTDIR)
            path=n+1;
        else {
            perror("find_path:  stat");
@@ -176,14 +176,17 @@ char *qualify(n)
        else if (!strcmp(beg, "."))
            ;                           /* ignore "." */
        else if (!strcmp(beg, "..")) {
-           tmp = rindex(full, '/');
-           if (tmp && tmp != &full[0])
+           if ((tmp = rindex(full, '/')))
                *tmp = '\0';
        } else {
            strcat(full, "/");
            strcat(full, beg);          /* copy in new component */
        }
 
+       /* if we used ../.. to go past the root dir just continue */
+       if (!full[0])
+           continue;
+
        /* check for symbolic links */
        if (lstat(full, &statbuf)) {
            perror("qualify:  lstat");
@@ -221,6 +224,10 @@ char *qualify(n)
        }
     } while (end);
 
+    /* if we resolved to "/" full[0] will be NULL */
+    if (!full[0])
+       strcpy(full, "/");
+
     return((char *)full);
 }