From: Eric Wong Date: Thu, 27 Mar 2025 23:20:44 +0000 (+0000) Subject: nntp: avoid uninitialized vars from bogus LIST args X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ce698d1583761eb5b0d0fd401ec615b7bc173625;p=thirdparty%2Fpublic-inbox.git nntp: avoid uninitialized vars from bogus LIST args We can only use the `list_' prefix in NNTP.pm for subcommands which we intend to dispatch from client requests. So prefix the list_*_i subs with a `_' to prevent `args_ok' from firing on a non-prototyped subroutine. I noticed this problem in the previous change to reduce code duplication between LIST subcommands. --- diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index cdfbd35c7..457e0fb7c 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -126,7 +126,7 @@ sub _list_groups (@) { $self->long_response($cb, names2ibx($self, \@names)); } -sub list_active_i { # "LIST ACTIVE" and also just "LIST" (no args) +sub _list_active_i { # "LIST ACTIVE" and also just "LIST" (no args) my ($self, $ibxs) = @_; my @window = splice(@$ibxs, 0, 1000); emit_group_lines($self, \@window); @@ -134,10 +134,10 @@ sub list_active_i { # "LIST ACTIVE" and also just "LIST" (no args) } sub list_active ($;$) { # called by cmd_list - _list_groups \&list_active_i, @_; + _list_groups \&_list_active_i, @_; } -sub list_active_times_i { +sub _list_active_times_i { my ($self, $ibxs) = @_; my @window = splice(@$ibxs, 0, 1000); $self->msg_more(join('', map { @@ -148,10 +148,10 @@ sub list_active_times_i { } sub list_active_times ($;$) { # called by cmd_list - _list_groups \&list_active_times_i, @_; + _list_groups \&_list_active_times_i, @_; } -sub list_newsgroups_i { +sub _list_newsgroups_i { my ($self, $ibxs) = @_; my @window = splice(@$ibxs, 0, 1000); $self->msg_more(join('', map { @@ -161,7 +161,7 @@ sub list_newsgroups_i { } sub list_newsgroups ($;$) { # called by cmd_list - _list_groups \&list_newsgroups_i, @_; + _list_groups \&_list_newsgroups_i, @_; } # LIST SUBSCRIPTIONS, DISTRIB.PATS are not supported @@ -178,7 +178,7 @@ sub cmd_list ($;$$) { $arg->($self, @args); } else { $self->msg_more("215 list of newsgroups follows\r\n"); - $self->long_response(\&list_active_i, names2ibx($self)); + $self->long_response(\&_list_active_i, names2ibx($self)); } } diff --git a/t/nntpd.t b/t/nntpd.t index 7052cb6a7..1b2a9fa9b 100644 --- a/t/nntpd.t +++ b/t/nntpd.t @@ -137,6 +137,16 @@ close $cfgfh or BAIL_OUT; syswrite($s, "NEWGROUPS\t19990424 000000 \033GMT\007\r\n"); is(0, sysread($s, $buf, 4096), 'GOT EOF on cntrl'); + # attempt to call _list_*_i subs directly + $s = tcp_connect($sock); + $buf = readline $s // xbail "readline: $!"; + like $buf, qr/\A201 .*? ready.*?\r\n/s, 'got greeting'; + for my $scmd (qw(ACTIVE ACTIVE.TIMES NEWSGROUPS)) { + print $s "LIST $scmd.I\r\n" or xbail "print $!"; + $buf = readline $s // xbail "readline: $!"; + like $buf, qr/\A501 /, "got 501 on bad command (LIST $scmd.I)"; + } + $s = tcp_connect($sock); sysread($s, $buf, 4096); is($buf, "201 " . hostname . " ready - post via email\r\n", @@ -395,6 +405,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000 <$fh>; }; unlike($eout, qr/wide/i, 'no Wide character warnings'); + unlike $eout, qr/uninitialized/i, 'no uninitialized warnings'; } $td = undef;