diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-05-30 20:40:31 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-05-30 20:40:31 +0000 |
commit | a5efb90134450569111e10f0159ec9b92df6ac4d (patch) | |
tree | 23c0b214ffd881898af0a575bebb37e6a648fb46 /lib | |
parent | 6519346a2658942d5829a998e2b77ce0bc492537 (diff) |
When changing directory to '..', verify that we really are where
we should be. This is similar to the old fts bug but happens when
popping out of directories, as opposed to descending into them.
Patch based on one by Kris Kennaway <kris@obsecurity.org>.
Issue reported by Nick Cleaton <nick@cleaton.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/fts.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 5d9c8aae5be..b5c65e84b75 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fts.c,v 1.25 2001/05/15 21:14:39 millert Exp $ */ +/* $OpenBSD: fts.c,v 1.26 2001/05/30 20:40:30 millert Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; #else -static char rcsid[] = "$OpenBSD: fts.c,v 1.25 2001/05/15 21:14:39 millert Exp $"; +static char rcsid[] = "$OpenBSD: fts.c,v 1.26 2001/05/30 20:40:30 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -271,6 +271,7 @@ fts_read(sp) FTS *sp; { FTSENT *p, *tmp; + struct stat sb; int instr; char *t; int saved_errno; @@ -443,8 +444,14 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent); return (NULL); } (void)close(p->fts_symfd); - } else if (!(p->fts_flags & FTS_DONTCHDIR)) { - if (CHDIR(sp, "..")) { + } else if (!(p->fts_flags & FTS_DONTCHDIR) && !ISSET(FTS_NOCHDIR)) { + if (chdir("..") || stat(".", &sb)) { + SET(FTS_STOP); + return (NULL); + } + if (sb.st_ino != p->fts_parent->fts_ino || + sb.st_dev != p->fts_parent->fts_dev) { + errno = ENOENT; SET(FTS_STOP); return (NULL); } |