]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Port short_read to UBSan
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 12 Jun 2025 07:20:52 +0000 (00:20 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 12 Jun 2025 07:21:48 +0000 (00:21 -0700)
Problem reported by Kirill Furman in:
https://lists.gnu.org/r/bug-tar/2025-06/msg00002.html
* src/buffer.c (short_read): Use (char *) record_start,
instead of record_start->buffer, to avoid undefined behavior
accessing past end of buffer.  In practice the undefined
behavior is harmless unless running with -fsanitize=undefined
or a similarly-picky implementation.

THANKS
src/buffer.c

diff --git a/THANKS b/THANKS
index 21ae387e5fce93f12411e08a37b29d4d1e92c017..20afca3876759ed1b8a93298c9b4f9ee2103786c 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -308,6 +308,7 @@ Kevin D Quitt               drs@netcom.com
 Kevin Dalley           kevin@aimnet.com
 Kimball Collins                kpc@ptolemy.arc.nasa.gov
 Kimmy Posey            kimmyd@bnr.ca
+Kirill Furman          kfurman@astralinux.ru
 Koji Kishi             kis@rqa.sony.co.jp
 Konno Hiroharu         konno@pac.co.jp
 Kurt Jaeger            pi@lf.net
index 1cdeffc6aa27da107891830bab269a9a2c11e9f1..2c40e9486bd597ffa9b7484f3dd01e34fc2d0a79 100644 (file)
@@ -959,11 +959,8 @@ archive_is_dev (void)
 static void
 short_read (idx_t status)
 {
-  idx_t left;                  /* bytes left */
-  char *more;                   /* pointer to next byte to read */
-
-  more = record_start->buffer + status;
-  left = record_size - status;
+  idx_t left = record_size - status;           /* bytes left to read */
+  char *more = (char *) record_start + status; /* address of next read */
 
   if (left && left % BLOCKSIZE == 0
       && (warning_option & WARN_RECORD_SIZE)