summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2006-09-29 16:52:48 +0000
committerJim Meyering <jim@meyering.net>2006-09-29 16:52:48 +0000
commita38becce9752e67f71e79e8c230b327869802e70 (patch)
treedfcc3eb484617775b630eb08486ec656d88948c4
parent31c77a2fde27888aead246cde6eb88724450e5e1 (diff)
downloadcoreutils-a38becce9752e67f71e79e8c230b327869802e70.tar.xz
* 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.
-rw-r--r--ChangeLog5
-rw-r--r--NEWS3
-rw-r--r--src/shuf.c2
-rwxr-xr-xtests/misc/shuf4
4 files changed, 13 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d22566f66..ac1cb0ee7 100644
--- 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 7d2eb9f8f..7a93f6313 100644
--- 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
diff --git a/src/shuf.c b/src/shuf.c
index 39cfdfffb..68003c259 100644
--- a/src/shuf.c
+++ b/src/shuf.c
@@ -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 ();
diff --git a/tests/misc/shuf b/tests/misc/shuf
index 585df9901..17a74dd3f 100755
--- a/tests/misc/shuf
+++ b/tests/misc/shuf
@@ -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