From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 84AF21F487 for ; Thu, 30 Nov 2023 11:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701344469; bh=90CU70wabFZ6OF9M1zNltbojd915ZeSSiKI5ApGkfbM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tsbwUZhzIcVoZcoVLPWfRs/sGvOcqSj27qcvq24dg+S4CJaky6la5FnSZwa0EI6xL SoFPNhCZ4aHks2mLoGQ4L/FyLgVwiIei/fPxE+QRYc0rA55qyMd89sC9S6GLuQqh4h QjLgm4MOarv/uelp+30QwHfzN1n7+499pQySf3Do= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/15] config: reject newlines consistently in dir names Date: Thu, 30 Nov 2023 11:40:56 +0000 Message-ID: <20231130114109.2577708-4-e@80x24.org> In-Reply-To: <20231130114109.2577708-1-e@80x24.org> References: <20231130114109.2577708-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Explicitly drop support for "\n" in git coderepo pathnames as we do other stuff. Gcf2 (our libgit2 helper) was always broken with "\n" in pathnames, and I'm not sure if cgit config files work with them, either. Dealing with newline characters requires extra complexity that I'm not willing to deal with when managing alternates files. --- lib/PublicInbox/Config.pm | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 779e3140..6bebf790 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -361,12 +361,19 @@ sub parse_cgitrc { cgit_repo_merge($self, $repo->{dir}, $repo) if $repo; } +sub valid_dir ($$) { + my $dir = get_1($_[0], $_[1]) // return; + index($dir, "\n") < 0 ? $dir : do { + warn "E: `$_[1]=$dir' must not contain `\\n'\n"; + undef; + } +} + # parse a code repo, only git is supported at the moment sub fill_coderepo { my ($self, $nick) = @_; my $pfx = "coderepo.$nick"; - my $dir = $self->{"$pfx.dir"} // return undef; # aka "GIT_DIR" - my $git = PublicInbox::Git->new($dir); + my $git = PublicInbox::Git->new(valid_dir($self, "$pfx.dir") // return); if (defined(my $cgits = $self->{"$pfx.cgiturl"})) { $git->{cgit_url} = $cgits = _array($cgits); $self->{"$pfx.cgiturl"} = $cgits; @@ -450,18 +457,15 @@ sub _fill_ibx { my $v = $self->{"$pfx.$k"}; $ibx->{$k} = $v if defined $v; } - for my $k (qw(filter inboxdir newsgroup replyto httpbackendmax feedmax + for my $k (qw(filter newsgroup replyto httpbackendmax feedmax indexlevel indexsequentialshard boost)) { my $v = get_1($self, "$pfx.$k") // next; $ibx->{$k} = $v; } # "mainrepo" is backwards compatibility: - my $dir = $ibx->{inboxdir} //= $self->{"$pfx.mainrepo"} // return; - if (index($dir, "\n") >= 0) { - warn "E: `$dir' must not contain `\\n'\n"; - return; - } + my $dir = $ibx->{inboxdir} = valid_dir($self, "$pfx.inboxdir") // + valid_dir($self, "$pfx.mainrepo") // return; for my $k (qw(obfuscate)) { my $v = $self->{"$pfx.$k"} // next; if (defined(my $bval = git_bool($v))) { @@ -548,12 +552,8 @@ sub _fill_ei ($$) { my ($self, $name) = @_; eval { require PublicInbox::ExtSearch } or return; my $pfx = "extindex.$name"; - my $d = $self->{"$pfx.topdir"} // return; + my $d = valid_dir($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 = get_1($self, "$pfx.$k") // next; @@ -573,12 +573,8 @@ sub _fill_csrch ($$) { return if $name ne '' && !valid_foo_name($name, 'cindex'); eval { require PublicInbox::CodeSearch } or return; my $pfx = "cindex.$name"; - my $d = $self->{"$pfx.topdir"} // return; + my $d = valid_dir($self, "$pfx.topdir") // return; -d $d or return; - if (index($d, "\n") >= 0) { - warn "E: `$d' must not contain `\\n'\n"; - return; - } my $csrch = PublicInbox::CodeSearch->new($d, $self); for my $k (qw(localprefix)) { my $v = $self->{"$pfx.$k"} // next;