]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
pr: fix infinite loop when double spacing
authorPádraig Brady <P@draigBrady.com>
Tue, 25 Apr 2023 13:07:03 +0000 (14:07 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 25 Apr 2023 13:18:35 +0000 (14:18 +0100)
* src/pr.c (init_parameters): Ensure we avoid a 0 lines_per_body
which was possible when adjusting for double spacing.
That caused print_page() to always return true,
causing an infinite loop.
* tests/pr/pr-tests.pl: Add a test case.
* NEWS: Mention the fix.
Fixes https://bugs.debian.org/1034808

NEWS
src/pr.c
tests/pr/pr-tests.pl

diff --git a/NEWS b/NEWS
index f6f79ae530990fe3171d2dd300ffeabf57f50565..3d34a1b3c59e40e617fe812a0d04117eb1b42b90 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   factor, numfmt, and tsort now diagnose read errors on the input.
   [This bug was present in "the beginning".]
 
+  'pr --length=1 --double-space' no longer enters an infinite loop.
+  [This bug was present in "the beginning".]
+
 ** Changes in behavior
 
   'cp -v' and 'mv -v' will no longer output a message for each file skipped
index 2c5cdceb1179083802fe9f417f4e33c36adbf8cd..14a368b6c9ce8f38781ad5943d3d91ee510e3917 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
@@ -1209,7 +1209,7 @@ init_parameters (int number_of_files)
     lines_per_body = lines_per_page;
 
   if (double_space)
-    lines_per_body = lines_per_body / 2;
+    lines_per_body = MAX (1, lines_per_body / 2);
 
   /* If input is stdin, cannot print parallel files.  BSD dumps core
      on this. */
index 265e6e108b52a16a82e6be20217dbf1f7b565bb8..eafc13d8160bd41dd3dd80ace17733f9e583f7b7 100755 (executable)
@@ -415,6 +415,9 @@ my @tv = (
 ['padding2', '-t -n,64', "1\n", (" "x 63)."1,1\n", 0],
 # Ensure we handle buffer truncation correctly
 ['padding3', '-t -N1000000 -n,1', "1\n", "0,1\n", 0],
+
+# This entered an infinite loop before coreutils-9.4
+['page-length1', '-dl1', "", "", 0],
 );
 
 # Convert the above old-style test vectors to the newer