user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH] config: reject `\n' in `inboxdir'
Date: Fri, 17 Jul 2020 06:07:10 +0000	[thread overview]
Message-ID: <20200717060710.12672-1-e@yhbt.net> (raw)

"\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);

                 reply	other threads:[~2020-07-17  6:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200717060710.12672-1-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH] config: reject `\n'\'' in `inboxdir'\''' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git