]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: disallow "\n" in local externals paths
authorEric Wong <e@80x24.org>
Fri, 19 Mar 2021 12:35:56 +0000 (10:35 -0200)
committerEric Wong <e@80x24.org>
Fri, 19 Mar 2021 12:46:56 +0000 (12:46 +0000)
git 2.11 and earlier could not handle git directories with
newlines in them, nor does libgit2 support them.

Followup-to: d87dd0e679587043 ("config: reject `\n' in `inboxdir'")
lib/PublicInbox/LeiExternal.pm
lib/PublicInbox/LeiXSearch.pm
t/lei-externals.t
t/lei-mirror.t
t/lei.t

index 47791d4e21ba0d2d67e48f99aadfbcce13752ce5..b5dd85e158b18f007cf53f97e6e6c08f896430e0 100644 (file)
@@ -170,9 +170,14 @@ sub lei_add_external {
                $self->fail(<<""); # TODO: did you mean "update-external?"
 --mirror destination `$location' already exists
 
+       } elsif (-d $location) {
+               index($location, "\n") >= 0 and
+                       return $self->fail("`\\n' not allowed in `$location'");
        }
        if ($location !~ m!\Ahttps?://! && !-d $location) {
                $mirror // return $self->fail("$location not a directory");
+               index($location, "\n") >= 0 and
+                       return $self->fail("`\\n' not allowed in `$location'");
                $mirror = ext_canonicalize($mirror);
                require PublicInbox::LeiMirror;
                PublicInbox::LeiMirror->start($self, $mirror => $location);
index 22c8026cd98c678fab5616dc22d0b8b746f1e718..d95a218e0d1878c283d8e8738c7a5c80f7345840 100644 (file)
@@ -502,8 +502,10 @@ sub prepare_external {
                return add_uri($self, URI->new($loc));
        } elsif (-f "$loc/ei.lock") {
                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") {
+               die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
                require PublicInbox::Inbox; # v2, v1
                $loc = bless { inboxdir => $loc }, 'PublicInbox::Inbox';
        } else {
index 2a92d1016d885a37e5f3a325a9bdecfc495b643d..1695ff0be970acb232b7710cef5798ae0faa3372 100644 (file)
@@ -78,8 +78,12 @@ test_lei(sub {
        ok(!-e $config_file && !-e $store_dir,
                'nothing created by ls-external');
 
-       ok(!lei('add-external', "$home/nonexistent",
-               "fails on non-existent dir"));
+       ok(!lei('add-external', "$home/nonexistent"),
+               "fails on non-existent dir");
+       like($lei_err, qr/not a directory/, 'noted non-existence');
+       mkdir "$home/new\nline" or BAIL_OUT "mkdir: $!";
+       ok(!lei('add-external', "$home/new\nline"), "fails on newline");
+       like($lei_err, qr/`\\n' not allowed/, 'newline noted in error');
        lei_ok('ls-external', \'ls-external works after add failure');
        is($lei_out.$lei_err, '', 'ls-external still has no output');
        my $cfg = PublicInbox::Config->new($cfg_path);
index 1d113e3ed1b34968528ed3fd7cfb22b379aa7166..9769f31bdc3fe1efd8d2566fe5deefd0e5d9b163 100644 (file)
@@ -29,8 +29,13 @@ test_lei({ tmpdir => $tmpdir }, sub {
        ok(!lei('add-external', $t2, '--mirror', "$http/t2/"),
                '--mirror fails if reused') or diag "$lei_err.$lei_out = $?";
 
+       ok(!lei('add-external', "$home/t2\nnewline", '--mirror', "$http/t2/"),
+               '--mirror fails on newline');
+       like($lei_err, qr/`\\n' not allowed/, 'newline noted in error');
+
        lei_ok('ls-external');
        like($lei_out, qr!\Q$t2\E!, 'still in ls-externals');
+       unlike($lei_out, qr!\Qnewline\E!, 'newline entry not added');
 
        ok(!lei('add-external', "$t2-fail", '-Lmedium'), '--mirror v2');
        ok(!-d "$t2-fail", 'destination not created on failure');
diff --git a/t/lei.t b/t/lei.t
index 74a775ca30884f72677d441bfd325d5b207f5737..2bf4b862557dd8ca6d4599b9d81907064cded29c 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -133,6 +133,18 @@ my $test_fail = sub {
        is($? >> 8, 1, 'chdir at end fails to /dev/null');
        lei('-C', '/dev/null', 'q', 'whatever');
        is($? >> 8, 1, 'chdir at beginning fails to /dev/null');
+
+       for my $lk (qw(ei inbox)) {
+               my $d = "$home/newline\n$lk";
+               mkdir $d;
+               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'),
+                               "newline $lk.lock fails with q $fl");
+                       like($lei_err, qr/`\\n' not allowed/,
+                               "error noted with q $fl");
+               }
+       }
 SKIP: {
        skip 'no curl', 3 unless which('curl');
        lei(qw(q --only http://127.0.0.1:99999/bogus/ t:m));