]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
od: fix theoretical size_t malloc overflow
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 28 Jun 2025 15:15:42 +0000 (08:15 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Jun 2025 04:00:40 +0000 (21:00 -0700)
* src/od.c (dump, dump_strings): Use idx_t allocators
rather than size_t allocators, to avoid unchecked integer
overflow on theoretical platforms where SIZE_MAX < IDX_MAX.

src/od.c

index 6b5c8675f1390da9792983db5e41b900649e38df..7306b0f9ad4b7b59aa18b71158302114ad427eca 100644 (file)
--- a/src/od.c
+++ b/src/od.c
@@ -1432,7 +1432,7 @@ dump (void)
   bool ok = true;
   size_t n_bytes_read;
 
-  block[0] = xnmalloc (2, bytes_per_block);
+  block[0] = xinmalloc (2, bytes_per_block);
   block[1] = block[0] + bytes_per_block;
 
   current_offset = n_bytes_to_skip;
@@ -1514,7 +1514,7 @@ static bool
 dump_strings (void)
 {
   idx_t bufsize = MAX (100, string_min + 1);
-  char *buf = xmalloc (bufsize);
+  char *buf = ximalloc (bufsize);
   uintmax_t address = n_bytes_to_skip;
   bool ok = true;