From: Todd C. Miller Date: Sun, 5 Sep 1993 13:55:34 +0000 (+0000) Subject: now handles decending below '/' correctly X-Git-Tag: SUDO_1_3_0~96 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3636ccc41876364a595420205091c76300e7231;p=sudo now handles decending below '/' correctly --- diff --git a/find_path.c b/find_path.c index 5ef36ff73..c88ae80b0 100644 --- a/find_path.c +++ b/find_path.c @@ -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); }