Applied patch from "Chris L. Mason" <cmason@somanetworks.com> to prevent

filesystem traversal.

Return immediately if we cannot chdir back to the directory we came
from.
This commit is contained in:
hjp 2002-02-25 23:23:10 +00:00
parent 22489c6971
commit 60b99b5cde
1 changed files with 15 additions and 1 deletions

View File

@ -23,12 +23,18 @@ sub cleandir {
return; return;
} }
my $std = lstat("."); my $std = lstat(".");
my $fs = $std->dev;
for my $i (readdir(DIR)) { for my $i (readdir(DIR)) {
if ($i eq "." || $i eq "..") {next} if ($i eq "." || $i eq "..") {next}
if ($verbose > 2) { if ($verbose > 2) {
print STDERR "$0:", " " x $level, " checking $dir/$i\n"; print STDERR "$0:", " " x $level, " checking $dir/$i\n";
} }
my $st = lstat("$i"); my $st = lstat("$i");
# Skip anything on a different filesystem
next if ($st->dev != $fs);
if ($verbose > 3) { if ($verbose > 3) {
print STDERR "$0:", " " x $level, " mtime=", $st->mtime, " atime=", $st->atime, "\n"; print STDERR "$0:", " " x $level, " mtime=", $st->mtime, " atime=", $st->atime, "\n";
} }
@ -56,6 +62,7 @@ sub cleandir {
" to ", " to ",
$std1->dev, "/", $std1->ino, $std1->dev, "/", $std1->ino,
"\n"; "\n";
return ++$notremoved;
} }
if ($remaining == 0 && $st->mtime < $since) { if ($remaining == 0 && $st->mtime < $since) {
if ($verbose > 0) { if ($verbose > 0) {
@ -113,7 +120,14 @@ sub main {
main(); main();
# $Log: cleandir,v $ # $Log: cleandir,v $
# Revision 1.4 2000-11-20 21:10:08 hjp # Revision 1.5 2002-02-25 23:23:10 hjp
# Applied patch from "Chris L. Mason" <cmason@somanetworks.com> to prevent
# filesystem traversal.
#
# Return immediately if we cannot chdir back to the directory we came
# from.
#
# Revision 1.4 2000/11/20 21:10:08 hjp
# Checks introduced in last version prevented deletion of unused subdirs. # Checks introduced in last version prevented deletion of unused subdirs.
# Fixed. # Fixed.
# #