From: Pádraig Brady
Date: Wed, 25 Feb 2026 14:49:12 +0000 (+0000) Subject: tests: factor,numfmt: verify embedded NUL handling X-Git-Tag: v9.11~225 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f06beebd340311ce8771d9b1f7f2b4416c5c01d8;p=thirdparty%2Fcoreutils.git tests: factor,numfmt: verify embedded NUL handling * tests/factor/factor.pl: Verify that embedded NULs on stdin terminate the _number_. * tests/numfmt/numfmt.p: Verify that embedded NULs on stdin terminate the _line_. https://github.com/coreutils/coreutils/pull/196 --- diff --git a/tests/factor/factor.pl b/tests/factor/factor.pl index fa38202427..2b8e540869 100755 --- a/tests/factor/factor.pl +++ b/tests/factor/factor.pl @@ -97,6 +97,13 @@ my @Tests = {OUT => '4999 340282366920938463463374607431768211297'}], ['h-1', '-h 3000', {OUT => '2^3 3 5^3'}], ['h-2', '3000 --exponents', {OUT => '2^3 3 5^3'}], + ['nul1', {IN_PIPE => '3'}, {OUT => '3'}], + ['nul2', {IN_PIPE => "3\000"}, {OUT => '3'}], + ['nul3', {IN_PIPE => "3\000foo"}, {OUT => '3'}], + ['nul4', {IN_PIPE => "3\000foo bar"}, {OUT => "3: 3\n"}, + {EXIT => 1}, + {ERR => "$prog: 'bar' is not a valid positive integer\n"}], + # ['nul5', "3\000"}, {OUT => '3'}], # Not supported by perl framework ); @@ -107,8 +114,22 @@ my $t; Test: foreach $t (@Tests) { - (my $arg1 = $t->[1]) =~ s| *\+?||; # strip '+' - ($arg1 = $arg1) =~ s| *-[^ ]+ *||; # strip option + my $arg1; + + # For IN_PIPE tests, the input number comes from the pipe, not $t->[1]. + foreach my $e (@$t) + { + ref $e eq 'HASH' && exists $e->{IN_PIPE} + and $arg1 = $e->{IN_PIPE}; + } + if (!defined $arg1) + { + $arg1 = $t->[1]; + } + + $arg1 =~ s| *\+?||; # strip '+' + $arg1 =~ s| *-[^ ]+ *||; # strip option + $arg1 =~ s|\0[^ \t\n]*||g; # strip NUL to whitespace # Don't fiddle with expected OUT string if there's a nonzero exit status. foreach my $e (@$t) diff --git a/tests/numfmt/numfmt.pl b/tests/numfmt/numfmt.pl index c999923cae..b899a46f54 100755 --- a/tests/numfmt/numfmt.pl +++ b/tests/numfmt/numfmt.pl @@ -43,7 +43,8 @@ my @Tests = ['5.1', '--from=iec-i 1Ki', {OUT => "1024"}], ['5.2', '--from=iec-i 1', {OUT => "1"}], - ['6', {IN_PIPE => "1234\n"}, {OUT => "1234"}], + ['6', {IN_PIPE => "1234\n"}, {OUT => "1234"}], + ['6nul', {IN_PIPE => "1234\000foo bar\n"},{OUT => "1234"}], ['7', '--from=si', {IN_PIPE => "2K\n"}, {OUT => "2000"}], ['7a', '--invalid=fail', {IN_PIPE => "no_NL"}, {OUT => "no_NL"}, {ERR => "$prog: invalid number: 'no_NL'\n"},