components/coreutils/patches/fix-od.patch
author Rich Burridge <rich.burridge@oracle.com>
Thu, 15 May 2014 16:58:20 -0700
changeset 1898 5c902a3c6e7e
parent 1326 6edae69990a7
permissions -rw-r--r--
18744156 /usr/gnu/bin/chroot is killed when executed with an invalid command argument

Fix for CR #16833210 - god does not handle large values of -w well

GNU od -wN with N larger than 64K on a system with 32-bit size_t would
print approximately 2*N bytes of extraneous padding.
[Bug introduced in coreutils-7.0]

From: Jim Meyering <address@hidden>
Date: Sat, 1 Jun 2013 19:20:06 -0700
Subject: [PATCH] od: -wN, N>64K, avoid misbehavior on systems with 32-bit
 size_t

* src/od.c (PRINT_FIELDS): Declare "i" to be of type uintmax_t, so that
the numerator in the expression for "next_pad" does not overflow.
(print_named_ascii): Likewise.
(print_ascii): Likewise.
Bug introduced via commit v6.12-42-g20c0b87.
* tests/misc/od.pl: Exercise each of the three affected code paths.
* NEWS (Bug fixes): Mention it.
Reported by Rich Burridge.
---
 NEWS             | 4 ++++
 THANKS.in        | 1 +
 src/od.c         | 6 +++---
 tests/misc/od.pl | 7 +++++++
 4 files changed, 15 insertions(+), 3 deletions(-)

Also see the email thread at:
http://lists.gnu.org/archive/html/bug-coreutils/2013-06/msg00009.html

--- coreutils-8.16/src/od.c.orig	2013-06-03 06:32:09.966956225 -0700
+++ coreutils-8.16/src/od.c	2013-06-03 07:15:29.690420676 -0700
@@ -394,7 +394,7 @@
    char const *FMT_STRING, int width, int pad)                          \
 {                                                                       \
   T const *p = block;                                                   \
-  size_t i;                                                             \
+  uintmax_t i;                                                          \
   int pad_remaining = pad;                                              \
   for (i = fields; blank < i; i--)                                      \
     {                                                                   \
@@ -450,7 +450,7 @@
                    int width, int pad)
 {
   unsigned char const *p = block;
-  size_t i;
+  uintmax_t i;
   int pad_remaining = pad;
   for (i = fields; blank < i; i--)
     {
@@ -481,7 +481,7 @@
              int pad)
 {
   unsigned char const *p = block;
-  size_t i;
+  uintmax_t i;
   int pad_remaining = pad;
   for (i = fields; blank < i; i--)
     {
--- coreutils-8.16/tests/misc/od.orig	2013-06-03 06:34:10.913221535 -0700
+++ coreutils-8.16/tests/misc/od	2013-06-03 06:34:46.766226767 -0700
@@ -57,6 +57,14 @@
      # even if the kernel reports that the file has stat.st_size = 0.
      ['j-proc', "-An -c -j $proc_file_byte_count $proc_file",
                                {IN=>{f2=>'e'}}, {OUT=>"   e\n"}],
+
+     # Ensure that a large width does not cause trouble.
+     # From coreutils-7.0 through coreutils-8.21, these would print
+     # approximately 128KiB of padding.
+     ['wide-a',   '-a -w65537 -An', {IN=>{g=>'x'}}, {OUT=>"   x\n"}],
+     ['wide-c',   '-c -w65537 -An', {IN=>{g=>'x'}}, {OUT=>"   x\n"}],
+     ['wide-x', '-tx1 -w65537 -An', {IN=>{g=>'B'}}, {OUT=>" 42\n"}],
+
     );
 
 my $save_temps = $ENV{DEBUG};