]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
git: packed_bytes: deal with glob+stat TOCTTOU
authorEric Wong <e@80x24.org>
Sun, 1 Oct 2023 09:54:21 +0000 (09:54 +0000)
committerEric Wong <e@80x24.org>
Sun, 1 Oct 2023 22:41:44 +0000 (22:41 +0000)
There's not much we can do about this aside from just ignoring
errors and considering un-stat-able files as zero-sized.
There's no syscalls which expose FUSE3 `readdirplus' type
functionality to userspace to avoid this problem.

lib/PublicInbox/Git.pm

index 1dbd10b7701c02527336368016a58090856274b3..0fd621e1cb6bc7ef9b65c39f6f52b6272dd93e39 100644 (file)
@@ -486,9 +486,7 @@ sub packed_bytes {
        my ($self) = @_;
        my $n = 0;
        my $pack_dir = git_path($self, 'objects/pack');
-       foreach my $p (bsd_glob("$pack_dir/*.pack", GLOB_NOSORT)) {
-               $n += -s $p;
-       }
+       $n += (-s $_ // 0) for (bsd_glob("$pack_dir/*.pack", GLOB_NOSORT));
        $n
 }