]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
od: -wN, N>64K, avoid misbehavior on systems with 32-bit size_t
authorJim Meyering <meyering@fb.com>
Sun, 2 Jun 2013 02:20:06 +0000 (19:20 -0700)
committerJim Meyering <meyering@fb.com>
Sun, 2 Jun 2013 16:25:38 +0000 (09:25 -0700)
* 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
THANKS.in
src/od.c
tests/misc/od.pl

diff --git a/NEWS b/NEWS
index 721e05bf59773b8e0ee2f933ffee14944fa77be7..cad5eee38dd04b6e068e0347fcc6429ea1bcbde4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   system such as GNU/Linux where directory ACL umasks override process umasks.
   [bug introduced in coreutils-6.0]
 
+  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]
+
   tail --retry -f now waits for the files specified to appear.  Before, tail
   would immediately exit when such a file is inaccessible during the initial
   open.
index 67b60b9fdf6455094f5b5de12b1e11cfabd49b1a..f399d77147e65836d73baaef8a41a1dd2bb1c932 100644 (file)
--- a/THANKS.in
+++ b/THANKS.in
@@ -521,6 +521,7 @@ Ralph Loader                        loader@maths.ox.ac.uk
 Rasmus Borup Hansen                 rbh@intomics.com
 Raul Miller                         moth@magenta.com
 Raúl Núñez de Arenas Coronado       raul@pleyades.net
+Rich Burridge                       rich.burridge@oracle.com
 Richard A Downing                   richard.downing@bcs.org.uk
 Richard Braakman                    dark@xs4all.nl
 Richard Dawe                        rich@phekda.freeserve.co.uk
index e8cab46ab6b4960d92206f082e5e9fd6140def90..1c234015f6d9ae5260cb3eb879e59d27466047a5 100644 (file)
--- a/src/od.c
+++ b/src/od.c
@@ -400,7 +400,7 @@ N (size_t fields, size_t blank, void const *block,                      \
    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--)                                      \
     {                                                                   \
@@ -456,7 +456,7 @@ print_named_ascii (size_t fields, size_t blank, void const *block,
                    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--)
     {
@@ -487,7 +487,7 @@ print_ascii (size_t fields, size_t blank, void const *block,
              int pad)
 {
   unsigned char const *p = block;
-  size_t i;
+  uintmax_t i;
   int pad_remaining = pad;
   for (i = fields; blank < i; i--)
     {
index 0649b1c62aa0fff871c02ddda593984d2be53a2a..fb579aa90d25031b6ad6e62885815894f7a31c38 100755 (executable)
@@ -57,6 +57,13 @@ my @Tests =
      # 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};