diff options
Diffstat (limited to 'contrib/tcsh/sh.dir.c')
-rw-r--r-- | contrib/tcsh/sh.dir.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/contrib/tcsh/sh.dir.c b/contrib/tcsh/sh.dir.c index de2e9d0..4271be2 100644 --- a/contrib/tcsh/sh.dir.c +++ b/contrib/tcsh/sh.dir.c @@ -1,4 +1,4 @@ -/* $Header: /src/pub/tcsh/sh.dir.c,v 3.56 2001/01/29 01:28:02 christos Exp $ */ +/* $Header: /src/pub/tcsh/sh.dir.c,v 3.60 2002/07/08 21:03:04 christos Exp $ */ /* * sh.dir.c: Directory manipulation functions */ @@ -14,11 +14,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +32,7 @@ */ #include "sh.h" -RCSID("$Id: sh.dir.c,v 3.56 2001/01/29 01:28:02 christos Exp $") +RCSID("$Id: sh.dir.c,v 3.60 2002/07/08 21:03:04 christos Exp $") /* * C Shell - directory management @@ -323,6 +319,7 @@ dnormalize(cp, exp) if (exp) { int dotdot = 0; Char *dp, *cwd, *start = cp, buf[MAXPATHLEN]; + struct stat sb; # ifdef apollo bool slashslash; # endif /* apollo */ @@ -339,6 +336,13 @@ dnormalize(cp, exp) if (dotdot == 0) return (Strsave(cp)); + /* + * If the path doesn't exist, we are done too. + */ + if (lstat(short2str(cp), &sb) != 0 && errno == ENOENT) + return (Strsave(cp)); + + cwd = (Char *) xmalloc((size_t) (((int) Strlen(dcwd->di_name) + 3) * sizeof(Char))); (void) Strcpy(cwd, dcwd->di_name); @@ -415,6 +419,18 @@ dnormalize(cp, exp) if ((TRM(cwd[(dotdot = (int) Strlen(cwd)) - 1])) == '/') cwd[--dotdot] = '\0'; } + /* Reduction of ".." following the stuff we collected in buf + * only makes sense if the directory item in buf really exists. + * Avoid reduction of "-I../.." (typical compiler call) to "" + * or "/usr/nonexistant/../bin" to "/usr/bin": + */ + if (cwd[0]) { + struct stat exists; + if (0 != stat(short2str(cwd), &exists)) { + xfree((ptr_t) cwd); + return Strsave(start); + } + } if (!*cp) break; } @@ -570,7 +586,7 @@ dfollow(cp) } if (cp[0] != '/' && !prefix(STRdotsl, cp) && !prefix(STRdotdotsl, cp) - && (c = adrof(STRcdpath))) { + && (c = adrof(STRcdpath)) && c->vec != NULL) { Char **cdp; register Char *p; Char buf[MAXPATHLEN]; @@ -1201,7 +1217,7 @@ dsetstack() struct varent *vp; struct directory *dn, *dp; - if ((vp = adrof(STRdirstack)) == NULL) + if ((vp = adrof(STRdirstack)) == NULL || vp->vec == NULL) return; /* Free the whole stack */ |