>From bb3b32b2d0a488fbaa146de062aafc762f974577 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 5 Jan 2015 19:40:03 -0800 Subject: [PATCH] shuf: do not mishandle 'shuf -i0-0 1' Problem reported by Daiki Ueno in: http://bugs.gnu.org/19520 * src/shuf.c (main): Avoid core dump if !input_range. * tests/misc/shuf.sh: Test for this bug. --- src/shuf.c | 2 +- tests/misc/shuf.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/shuf.c b/src/shuf.c index 75211bd..9db027c 100644 --- a/src/shuf.c +++ b/src/shuf.c @@ -501,7 +501,7 @@ main (int argc, char **argv) } if (input_range ? 0 < n_operands : !echo && 1 < n_operands) { - error (0, 0, _("extra operand %s"), quote (operand[1])); + error (0, 0, _("extra operand %s"), quote (operand[!input_range])); usage (EXIT_FAILURE); } diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh index 7e77102..5e85d9a 100755 --- a/tests/misc/shuf.sh +++ b/tests/misc/shuf.sh @@ -47,6 +47,10 @@ test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; } shuf -er test $? -eq 1 || fail=1 +# coreutils-8.23 dumps core. +shuf -i0-0 1 +test $? -eq 1 || fail=1 + # Before coreutils-6.3, this would infloop. # "seq 1860" produces 8193 (8K + 1) bytes of output. seq 1860 | shuf > /dev/null || fail=1 -- 2.1.0