]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
nntp: avoid uninitialized vars from bogus LIST args
authorEric Wong <e@80x24.org>
Thu, 27 Mar 2025 23:20:44 +0000 (23:20 +0000)
committerEric Wong <e@80x24.org>
Sun, 30 Mar 2025 18:19:31 +0000 (18:19 +0000)
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.

lib/PublicInbox/NNTP.pm
t/nntpd.t

index cdfbd35c780860536671bad7cf96b3ab04906eb6..457e0fb7c736bed77dc3c02db33c82c43a24fb5a 100644 (file)
@@ -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));
        }
 }
 
index 7052cb6a77297eafaa832eb34d7b4ae1ba7ac6b8..1b2a9fa9bbd59d2e39dd7962018f77d4d6a4dfa0 100644 (file)
--- 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;