]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei q: disallow "\n" in argv[] elements
authorEric Wong <e@80x24.org>
Wed, 10 Nov 2021 10:28:37 +0000 (10:28 +0000)
committerEric Wong <e@80x24.org>
Wed, 10 Nov 2021 18:38:16 +0000 (18:38 +0000)
I don't expect this to be hit in real-world use via normal
interactive shells.  However, somebody could accidentally add
"\n" in languages (e.g. Perl, C) where it's easy to pass "\n"
in argv[].

lib/PublicInbox/LeiQuery.pm
t/lei.t

index 352ee60131aaf6bc9baabfbd4ae735c4a0f06568..51ee3d9c83e47b1fed21f02a9cc02b51751d2507 100644 (file)
@@ -141,6 +141,7 @@ no query allowed on command-line with --stdin
                PublicInbox::InputPipe::consume($self->{0}, \&qstr_add, $self);
                return;
        }
+       chomp(@argv) and $self->qerr("# trailing `\\n' removed");
        $mset_opt{q_raw} = [ @argv ]; # copy
        $mset_opt{qstr} =
                $self->{lse}->query_argv_to_string($self->{lse}->git, \@argv);
diff --git a/t/lei.t b/t/lei.t
index f7de1b711a836827b5fdbbff40473ad408eb3fce..b10c9b59c72b8e29570b63dbf5853463a2c55cb7 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -143,6 +143,9 @@ my $test_fail = sub {
        lei('-C', '/dev/null', 'q', 'whatever');
        is($? >> 8, 1, 'chdir at beginning fails to /dev/null');
 
+       lei_ok('q', "foo\n");
+       like($lei_err, qr/trailing `\\n' removed/s, "noted `\\n' removal");
+
        for my $lk (qw(ei inbox)) {
                my $d = "$home/newline\n$lk";
                mkdir $d;