]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: stricter external checks for valid $GIT_DIR/objects
authorEric Wong <e@80x24.org>
Thu, 1 Dec 2022 11:21:31 +0000 (11:21 +0000)
committerEric Wong <e@80x24.org>
Fri, 2 Dec 2022 08:07:40 +0000 (08:07 +0000)
I ended up with my $HOME in
~/.cache/lei/all_locals_ever.git/objects/info/alterntes
and am trying to avoid that in the future.

lib/PublicInbox/LeiXSearch.pm
t/lei.t

index 90cb83b989feb6c1099b1213ff2937c2a0b38c2a..8e195c4c31cddf316859e25ef68504e7a034f16d 100644 (file)
@@ -617,11 +617,12 @@ sub prepare_external {
        } elsif ($loc =~ m!\Ahttps?://!) {
                require URI;
                return add_uri($self, URI->new($loc));
-       } elsif (-f "$loc/ei.lock") {
+       } elsif (-f "$loc/ei.lock" && -d "$loc/ALL.git/objects") {
                require PublicInbox::ExtSearch;
                die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
                $loc = PublicInbox::ExtSearch->new($loc);
-       } elsif (-f "$loc/inbox.lock" || -d "$loc/public-inbox") {
+       } elsif ((-f "$loc/inbox.lock" && -d "$loc/all.git/objects") ||
+                       (-d "$loc/public-inbox" && -d "$loc/objects")) {
                die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
                require PublicInbox::Inbox; # v2, v1
                $loc = bless { inboxdir => $loc }, 'PublicInbox::Inbox';
diff --git a/t/lei.t b/t/lei.t
index b10c9b59c72b8e29570b63dbf5853463a2c55cb7..a80143ef5cf6f58e3055f67e823367aacf40e803 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -148,7 +148,8 @@ my $test_fail = sub {
 
        for my $lk (qw(ei inbox)) {
                my $d = "$home/newline\n$lk";
-               mkdir $d;
+               my $all = $lk eq 'ei' ? 'ALL' : 'all';
+               File::Path::mkpath("$d/$all.git/objects");
                open my $fh, '>', "$d/$lk.lock" or BAIL_OUT "open $d/$lk.lock";
                for my $fl (qw(-I --only)) {
                        ok(!lei('q', $fl, $d, 'whatever'),