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 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 667E01F572 for ; Sat, 27 Jul 2024 08:37:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1722069468; bh=2Pxyux7m1BIdFnzYwMllzvWXsq82yNjezy3hwoR4x5s=; h=From:To:Subject:Date:From; b=iz52BI86KY9Y/rBcQ0FiT5wS+phAMBTB+4PPT2U5rS9k6sedAHH3fpaB8USi8pnwm 6IXoqmwl7bIxEI2767lv28LbjHonHinIbgw+NUJqFGVSucXdxK7iUAtlDmudRn0DxV hXRXFbkwLd+BwbIcwG40v1C1R1Jeg/6DKHTzA7Pw= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] *search: avoid HV modification on conditional assignment Date: Sat, 27 Jul 2024 08:37:48 +0000 Message-ID: <20240727083748.4159188-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Setting {qp} higher up the stack via `//=' is unsafe since ->qp_init_common calls ->xdb which can also set {xdb}, {nshard}, and {qp_flags}. While this doesn't fix any known bugs in current versions of Perl or our current code, it surfaced while working on new search features on our end. --- lib/PublicInbox/CodeSearch.pm | 2 +- lib/PublicInbox/MiscSearch.pm | 4 ++-- lib/PublicInbox/Search.pm | 6 +++--- lib/PublicInbox/XapHelper.pm | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/CodeSearch.pm b/lib/PublicInbox/CodeSearch.pm index e5fa4480..3838fd1b 100644 --- a/lib/PublicInbox/CodeSearch.pm +++ b/lib/PublicInbox/CodeSearch.pm @@ -159,7 +159,7 @@ sub roots_filter { # retry_reopen callback sub mset { my ($self, $qry_str, $opt) = @_; - my $qp = $self->{qp} //= qparse_new($self); + my $qp = $self->{qp} // qparse_new($self); my $qry = $qp->parse_query($qry_str, $self->{qp_flags}); # limit to commits with shared roots diff --git a/lib/PublicInbox/MiscSearch.pm b/lib/PublicInbox/MiscSearch.pm index 5fb47d03..ad7ebeb4 100644 --- a/lib/PublicInbox/MiscSearch.pm +++ b/lib/PublicInbox/MiscSearch.pm @@ -38,7 +38,7 @@ sub new { sub mi_qp_new ($) { my ($self) = @_; my $xdb = $self->{xdb}; - my $qp = $PublicInbox::Search::X{QueryParser}->new; + my $qp = $self->{qp} = $PublicInbox::Search::X{QueryParser}->new; $qp->set_default_op(PublicInbox::Search::OP_AND()); $qp->set_database($xdb); $qp->set_stemmer(PublicInbox::Search::stemmer($self)); @@ -76,7 +76,7 @@ sub mset { my ($self, $qs, $opt) = @_; $opt ||= {}; reopen($self); - my $qp = $self->{qp} //= mi_qp_new($self); + my $qp = $self->{qp} // mi_qp_new($self); $qs = 'type:inbox' if $qs eq ''; my $qr = $qp->parse_query($qs, $PublicInbox::Search::QP_FLAGS); $opt->{relevance} = 1 unless exists $opt->{relevance}; diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index eb5e67ba..649157be 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -413,7 +413,7 @@ sub query_approxidate { # read-only, for mail only (codesearch has different rules) sub mset { my ($self, $qry_str, $opt) = @_; - my $qp = $self->{qp} //= $self->qparse_new; + my $qp = $self->{qp} // $self->qparse_new; my $qry = $qp->parse_query($qry_str, $self->{qp_flags}); if (defined(my $eidx_key = $opt->{eidx_key})) { $qry = $X{Query}->new(OP_FILTER(), $qry, 'O'.$eidx_key); @@ -570,7 +570,7 @@ sub stemmer { $X{Stem}->new($LANG) } sub qp_init_common { my ($self) = @_; - my $qp = $X{QueryParser}->new; + my $qp = $self->{qp} = $X{QueryParser}->new; $qp->set_default_op(OP_AND()); $qp->set_database(xdb($self)); $qp->set_stemmer(stemmer($self)); @@ -654,7 +654,7 @@ EOM sub help { my ($self) = @_; - $self->{qp} //= $self->qparse_new; # parse altids + $self->{qp} // $self->qparse_new; # parse altids my @ret = @HELP; if (my $user_pfx = $self->{-user_pfx}) { push @ret, @$user_pfx; diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm index ba41b5d2..7e61631c 100644 --- a/lib/PublicInbox/XapHelper.pm +++ b/lib/PublicInbox/XapHelper.pm @@ -225,7 +225,7 @@ sub dispatch { } bless $new, $req->{c} ? 'PublicInbox::CodeSearch' : 'PublicInbox::Search'; - $new->{qp} = $new->qparse_new; + $new->qparse_new; $SRCH{$key} = $new; }; $req->{srch}->{xdb}->reopen unless $new;