]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Cleaner overflow checking in xheader_read
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 30 Jul 2024 23:21:39 +0000 (16:21 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Aug 2024 08:41:43 +0000 (01:41 -0700)
* src/xheader.c (xheader_read): Prefer ckd_add to
doing overflow checking by hand.

src/xheader.c

index e2b124b8282a130686b124e54a13cfd891b27d43..96762c34e141c848324eff4af4a60be2cbd836e5 100644 (file)
@@ -783,12 +783,13 @@ xheader_read (struct xheader *xhdr, union block *p, off_t size)
   if (size < 0)
     size = 0; /* Already diagnosed.  */
 
-  if (SIZE_MAX - BLOCKSIZE <= size)
+  size_t size_plus_1;
+  if (ckd_add (&size_plus_1, size, BLOCKSIZE + 1))
     xalloc_die ();
+  size = size_plus_1 - 1;
 
-  size += BLOCKSIZE;
   xhdr->size = size;
-  xhdr->buffer = xmalloc (size + 1);
+  xhdr->buffer = xmalloc (size_plus_1);
   xhdr->buffer[size] = '\0';
 
   do