Ticket #3550: coreutils-8.22-shuf-segfault.patch

File coreutils-8.22-shuf-segfault.patch, 2.2 KB (added by Miklos Karacsony, 11 years ago)
  • NEWS

    Submitted By:            Miklos Karacsony <mkaracsony81 at gmail dot com>
    Date:                    2014-04-22
    Initial Package Version: 8.22
    Upstream Status:         Applied
    Origin:                  Upstream
    Description:             shuf: with -r, don't dump core if the input is empty
    
    diff --git a/NEWS b/NEWS
    index e72942b..2df246d 100644
    a b GNU coreutils NEWS -*- outline -*-  
    2222  it would display an error, requiring --no-dereference to avoid the issue.
    2323  [bug introduced in coreutils-5.3.0]
    2424
     25  shuf -r no longer dumps core if the input is empty.
     26  [bug introduced in coreutils-8.22]
     27
    2528** New features
    2629
    2730  od accepts a new option: --endian=TYPE to handle inputs with different byte
  • src/shuf.c

    diff --git a/src/shuf.c b/src/shuf.c
    index d4641fe..2a91072 100644
    a b main (int argc, char **argv)  
    576576  /* Generate output according to requested method */
    577577  if (repeat)
    578578    {
    579       if (input_range)
    580         i = write_random_numbers (randint_source, head_lines,
    581                                   lo_input, hi_input, eolbyte);
     579      if (head_lines == 0)
     580        i = 0;
    582581      else
    583         i = write_random_lines (randint_source, head_lines, line, n_lines);
     582        {
     583          if (n_lines == 0)
     584            error (EXIT_FAILURE, 0, _("No lines to repeat"));
     585          if (input_range)
     586            i = write_random_numbers (randint_source, head_lines,
     587                                      lo_input, hi_input, eolbyte);
     588          else
     589            i = write_random_lines (randint_source, head_lines, line, n_lines);
     590        }
    584591    }
    585592  else
    586593    {
  • tests/misc/shuf.sh

    diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh
    index d3ea1f2..d7251d1 100755
    a b compare in out1 || { fail=1; echo "not a permutation" 1>&2; }  
    4343t=$(shuf -e a b c d e | sort | fmt)
    4444test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; }
    4545
     46# coreutils-8.22 dumps core.
     47shuf -er
     48test $? -eq 1 || fail=1
     49
    4650# Before coreutils-6.3, this would infloop.
    4751# "seq 1860" produces 8193 (8K + 1) bytes of output.
    4852seq 1860 | shuf > /dev/null || fail=1