user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 2/2] config: ignore extindex entries with newlines in paths
    2021-03-19 12:35  4% ` [PATCH 1/2] lei: disallow "\n" in local externals paths Eric Wong
@ 2021-03-19 12:35  6% ` Eric Wong
  1 sibling, 0 replies; 3+ results
From: Eric Wong @ 2021-03-19 12:35 UTC (permalink / raw)
  To: meta

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/Config.pm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 1037c884..770d9256 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -514,6 +514,10 @@ sub _fill_ei ($$) {
 	my $pfx = "extindex.$name";
 	my $d = $self->{"$pfx.topdir"} // return;
 	-d $d or return;
+	if (index($d, "\n") >= 0) {
+		warn "E: `$d' must not contain `\\n'\n";
+		return;
+	}
 	my $es = PublicInbox::ExtSearch->new($d);
 	for my $k (qw(indexlevel indexsequentialshard)) {
 		my $v = _one_val($self, $pfx, $k) // next;

^ permalink raw reply related	[relevance 6%]

* [PATCH 1/2] lei: disallow "\n" in local externals paths
  @ 2021-03-19 12:35  4% ` Eric Wong
  2021-03-19 12:35  6% ` [PATCH 2/2] config: ignore extindex entries with newlines in paths Eric Wong
  1 sibling, 0 replies; 3+ results
From: Eric Wong @ 2021-03-19 12:35 UTC (permalink / raw)
  To: meta

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 |  5 +++++
 lib/PublicInbox/LeiXSearch.pm  |  2 ++
 t/lei-externals.t              |  8 ++++++--
 t/lei-mirror.t                 |  5 +++++
 t/lei.t                        | 12 ++++++++++++
 5 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index 47791d4e..b5dd85e1 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -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);
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index 22c8026c..d95a218e 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -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 {
diff --git a/t/lei-externals.t b/t/lei-externals.t
index 2a92d101..1695ff0b 100644
--- a/t/lei-externals.t
+++ b/t/lei-externals.t
@@ -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);
diff --git a/t/lei-mirror.t b/t/lei-mirror.t
index 1d113e3e..9769f31b 100644
--- a/t/lei-mirror.t
+++ b/t/lei-mirror.t
@@ -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 74a775ca..2bf4b862 100644
--- 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));

^ permalink raw reply related	[relevance 4%]

* [PATCH] config: reject `\n' in `inboxdir'
@ 2020-07-17  6:07  7% Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2020-07-17  6:07 UTC (permalink / raw)
  To: meta

"\n" and other characters requiring quoting and/or escaping in
in $GIT_DIR/objects/info/alternates was not supported in git 2.11
and earlier; nor does it seem supported at all in libgit2.

This will allow us to support sharing git-cat-file or similar
endpoints across multiple inboxes via alternates.

This breaks an existing use case for anybody wacky
enough to put `\n' in the `inboxdir' pathname; but I doubt
this affects anybody.
---
 lib/PublicInbox/Config.pm |  5 ++++-
 script/public-inbox-init  |  1 +
 t/config.t                | 16 +++++++++++++---
 t/init.t                  |  8 ++++++++
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index c0e2cc57..67199bb3 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -393,7 +393,10 @@ sub _fill {
 
 	# backwards compatibility:
 	$ibx->{inboxdir} //= $self->{"$pfx.mainrepo"};
-
+	if (($ibx->{inboxdir} // '') =~ /\n/s) {
+		warn "E: `$ibx->{inboxdir}' must not contain `\\n'\n";
+		return;
+	}
 	foreach my $k (qw(obfuscate)) {
 		my $v = $self->{"$pfx.$k"};
 		defined $v or next;
diff --git a/script/public-inbox-init b/script/public-inbox-init
index c7f3da6f..951338af 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -115,6 +115,7 @@ my $pfx = "publicinbox.$name";
 my @x = (qw/git config/, "--file=$pi_config_tmp");
 
 $inboxdir = abs_path($inboxdir);
+die "`\\n' not allowed in `$inboxdir'\n" if $inboxdir =~ /\n/s;
 if (-f "$inboxdir/inbox.lock") {
 	if (!defined $version) {
 		$version = 2;
diff --git a/t/config.t b/t/config.t
index ad543ad3..d7fd9446 100644
--- a/t/config.t
+++ b/t/config.t
@@ -10,13 +10,23 @@ my ($tmpdir, $for_destroy) = tmpdir();
 
 {
 	PublicInbox::Import::init_bare($tmpdir);
-	my @cmd = ('git', "--git-dir=$tmpdir", qw(config foo.bar), "hi\nhi");
+	my $inboxdir = "$tmpdir/new\nline";
+	my @cmd = ('git', "--git-dir=$tmpdir",
+		qw(config publicinbox.foo.inboxdir), $inboxdir);
 	is(xsys(@cmd), 0, "set config");
 
 	my $tmp = PublicInbox::Config->new("$tmpdir/config");
 
-	is("hi\nhi", $tmp->{"foo.bar"}, "config read correctly");
-	is("true", $tmp->{"core.bare"}, "used --bare repo");
+	is($tmp->{'publicinbox.foo.inboxdir'}, $inboxdir,
+		'config read correctly');
+	is($tmp->{'core.bare'}, 'true', 'init used --bare repo');
+
+	my @warn;
+	local $SIG{__WARN__} = sub { push @warn, @_ };
+	$tmp = PublicInbox::Config->new("$tmpdir/config");
+	is($tmp->lookup_name('foo'), undef, 'reject invalid inboxdir');
+	like("@warn", qr/^E:.*must not contain `\\n'/sm,
+		'warned about newline');
 }
 
 {
diff --git a/t/init.t b/t/init.t
index 5c021be7..b8f17b5c 100644
--- a/t/init.t
+++ b/t/init.t
@@ -49,6 +49,14 @@ sub quiet_fail {
 	ok(unlink("$cfgfile.lock"),
 		'-init did not unlink lock on failure');
 }
+{
+	my $rdr = { 2 => \(my $err = '') };
+	my $cmd = [ '-init', 'alist', "$tmpdir/a\nlist",
+		   qw(http://example.com/alist alist@example.com) ];
+	ok(!run_script($cmd, undef, $rdr),
+		'public-inbox-init rejects LF in inboxdir');
+	like($err, qr/`\\n' not allowed in `/s, 'reported \\n');
+}
 
 SKIP: {
 	require_mods(qw(DBD::SQLite Search::Xapian::WritableDatabase), 2);

^ permalink raw reply related	[relevance 7%]

Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-07-17  6:07  7% [PATCH] config: reject `\n' in `inboxdir' Eric Wong
2021-03-19 12:35     [PATCH 0/2] newline rejection for new stuff Eric Wong
2021-03-19 12:35  4% ` [PATCH 1/2] lei: disallow "\n" in local externals paths Eric Wong
2021-03-19 12:35  6% ` [PATCH 2/2] config: ignore extindex entries with newlines in paths Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).