fix bugs in `find_src_files()`.
authorDavid Riebenbauer <davrieb@liegesta.at>
Wed, 3 Feb 2010 05:57:20 +0000 (06:57 +0100)
committerDavid Riebenbauer <davrieb@liegesta.at>
Wed, 3 Feb 2010 06:34:04 +0000 (07:34 +0100)
Use `_` to avoid superfluous stat.

Check for `defined $file`, instead of just `$file`.

Add spaces after commas.

Change return values of `verify_src_file()` to not return the tainted filename.
Rename `$f` to `$file_untainted in `verify_src_file()`.
$f changes to `$file` in `find_src_files()`.

This attempts to fix commit f3abeac919c4736429bd3362af6edf51ede8e7fe.
For discussion see
<http://ikiwiki.info/todo/auto-create_tag_pages_according_to_a_template/>

IkiWiki/Render.pm

index d2fa80fbb8fa5f1678627415548fa474ad11d0b0..5b72b6de1665a26d319aa3ee2664ad05a409a45b 100644 (file)
@@ -284,7 +284,7 @@ sub verify_src_file ($$) {
        my $file=decode_utf8(shift);
        my $dir=shift;
 
        my $file=decode_utf8(shift);
        my $dir=shift;
 
-       return if -l $file || -d $file;
+       return if -l $file || -d _;
        $file=~s/^\Q$dir\E\/?//;
        return if ! length $file;
        my $page = pagename($file);
        $file=~s/^\Q$dir\E\/?//;
        return if ! length $file;
        my $page = pagename($file);
@@ -294,11 +294,11 @@ sub verify_src_file ($$) {
                return;
        }
 
                return;
        }
 
-       my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
-       if (! defined $f) {
+       my ($file_untainted) = $file =~ /$config{wiki_file_regexp}/; # untaint
+       if (! defined $file_untainted) {
                warn(sprintf(gettext("skipping bad filename %s"), $file)."\n");
        }
                warn(sprintf(gettext("skipping bad filename %s"), $file)."\n");
        }
-       return ($file,$page,$f);
+       return ($file_untainted, $page);
 }
 
 sub find_src_files () {
 }
 
 sub find_src_files () {
@@ -309,8 +309,8 @@ sub find_src_files () {
        find({
                no_chdir => 1,
                wanted => sub {
        find({
                no_chdir => 1,
                wanted => sub {
-                       my ($file,$page,$f) = verify_src_file($_,$config{srcdir});
-                       if ($file) {
+                       my ($file, $page) = verify_src_file($_, $config{srcdir});
+                       if (defined $file) {
                                push @files, $file;
                                if ($pages{$page}) {
                                        debug(sprintf(gettext("%s has multiple possible source pages"), $page));
                                push @files, $file;
                                if ($pages{$page}) {
                                        debug(sprintf(gettext("%s has multiple possible source pages"), $page));
@@ -323,14 +323,14 @@ sub find_src_files () {
                find({
                        no_chdir => 1,
                        wanted => sub {
                find({
                        no_chdir => 1,
                        wanted => sub {
-                               my ($file,$page,$f) = verify_src_file($_,$dir);
-                               if ($f) {
+                               my ($file, $page) = verify_src_file($_, $dir);
+                               if (defined $file) {
                                        # avoid underlaydir override
                                        # attacks; see security.mdwn
                                        # avoid underlaydir override
                                        # attacks; see security.mdwn
-                                       if (! -l "$config{srcdir}/$f" &&
+                                       if (! -l "$config{srcdir}/$file" &&
                                            ! -e _) {
                                                if (! $pages{$page}) {
                                            ! -e _) {
                                                if (! $pages{$page}) {
-                                                       push @files, $f;
+                                                       push @files, $file;
                                                        $pages{$page}=1;
                                                }
                                        }
                                                        $pages{$page}=1;
                                                }
                                        }