my $content=$form->field('content');
$content=~s/\r\n/\n/g;
$content=~s/\r/\n/g;
- writefile("$config{srcdir}/$file", $content);
+ writefile($file, $config{srcdir}, $content);
my $message="web commit ";
if (length $session->param("name")) {
$content=htmlize($type, $content);
check_overwrite("$config{destdir}/".htmlpage($page), $page);
- writefile("$config{destdir}/".htmlpage($page),
+ writefile(htmlpage($page), $config{destdir},
genpage($content, $page, mtime($srcfile)));
$oldpagemtime{$page}=time;
$renderedfiles{$page}=htmlpage($page);
# check_overwrite, as above, but currently renderedfiles
# only supports listing one file per page.
if ($config{rss} && exists $inlinepages{$page}) {
- writefile("$config{destdir}/".rsspage($page),
+ writefile(rsspage($page), $config{destdir},
genrss($content, $page, mtime($srcfile)));
}
}
else {
$links{$file}=[];
check_overwrite("$config{destdir}/$file", $file);
- writefile("$config{destdir}/$file", $content);
+ writefile($file, $config{destdir}, $content);
$oldpagemtime{$file}=time;
$renderedfiles{$file}=$file;
}
again when saving the changed page.
This was fixed by making ikiwiki refuse to read or write to files that are
-symlinks, combined with the above locking.
+symlinks, or that are in subdirectories that are symlinks, combined with
+the above locking.
## underlaydir override attacks
return $ret;
} #}}}
-sub writefile ($$) { #{{{
- my $file=shift;
+sub writefile ($$$) { #{{{
+ my $file=shift; # can include subdirs
+ my $destdir=shift; # directory to put file in
my $content=shift;
- if (-l $file) {
- error("cannot write to a symlink ($file)");
+ my $test=$file;
+ while (length $test) {
+ if (-l "$destdir/$test") {
+ error("cannot write to a symlink ($test)");
+ }
+ $test=dirname($test);
}
- my $dir=dirname($file);
+ my $dir=dirname("$destdir/$file");
if (! -d $dir) {
my $d="";
foreach my $s (split(m!/+!, $dir)) {
}
}
- open (OUT, ">$file") || error("failed to write $file: $!");
+ open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!");
print OUT $content;
close OUT;
} #}}}