]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
shuf: do not mishandle 'shuf -i0-0 1'
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 6 Jan 2015 03:40:03 +0000 (19:40 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 6 Jan 2015 03:40:21 +0000 (19:40 -0800)
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
tests/misc/shuf.sh

index 75211bd4b158c226d5aa466ca27aaa75ba556824..9db027c183efc95507be88923ea8cae5cb4ca322 100644 (file)
@@ -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);
     }
 
index 7e7710254ef7326e9cface93f43d3168b16eab31..5e85d9acade070f102d64987c1f121b15ab78a17 100755 (executable)
@@ -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