]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
* src/shuf.c (read_input): Fix an off-by-one error that
authorJim Meyering <jim@meyering.net>
Fri, 29 Sep 2006 16:52:48 +0000 (16:52 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 29 Sep 2006 16:52:48 +0000 (16:52 +0000)
would cause an infloop for piped input of 8KB or more.
* NEWS: Mention the fix.
* tests/misc/shuf: Test for the above fix.

ChangeLog
NEWS
src/shuf.c
tests/misc/shuf

index d22566f667c77ec89d38f47a0a008b054fb58158..ac1cb0ee7b222656e86cd660a3aacaf4e3449d08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2006-09-29  Jim Meyering  <jim@meyering.net>
 
+       * src/shuf.c (read_input): Fix an off-by-one error that
+       would cause an infloop for piped input of 8KB or more.
+       * NEWS: Mention the fix.
+       * tests/misc/shuf: Test for the above fix.
+
        Since any system may be affected by the Darwin readdir bug,
        perform the extra rewinddir unconditionally.  The performance
        impact of rewinding a directory is negligible.
diff --git a/NEWS b/NEWS
index 7d2eb9f8f1a3406d58b3edc1b999cd673869df8b..7a93f6313375b1e0a59e70e27846e76181b3e4d4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,9 @@ GNU coreutils NEWS                                    -*- outline -*-
 
     "groups" now processes options like --help more compatibly.
 
+  shuf would infloop, given 8KB or more of piped input
+
+
 * Major changes in release 6.2 (2006-09-18) [stable candidate]
 
 ** Changes in behavior
index 39cfdfffb8469725be53d7b0f59b7a9bc28af6c7..68003c2593657f6d6c13f7ec2bfc1ae5be9284e4 100644 (file)
@@ -178,7 +178,7 @@ read_input (FILE *in, char eolbyte, char ***pline)
 
   do
     {
-      if (alloc == used)
+      if (alloc <= used + 1)
        {
          if (alloc == SIZE_MAX)
            xalloc_die ();
index 585df99017a9d3342461cb46a4e5c4bd6cda57c8..17a74dd3fef6b87042837eb7a355e7ab42b3984a 100755 (executable)
@@ -51,4 +51,8 @@ cmp in out > /dev/null && { fail=1; echo "not random?" 1>&2; }
 sort -n out > out1
 cmp in out1 || { fail=1; echo "not a permutation" 1>&2; }
 
+# Before coreutils-6.3, this would infloop.
+# "seq 1860" produces 8193 bytes of output.
+seq 1860 | shuf > /dev/null || fail=1
+
 (exit $fail); exit $fail