]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Prefer stdckdint.h to intprops.h
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 31 Jul 2024 00:59:04 +0000 (17:59 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Aug 2024 08:41:43 +0000 (01:41 -0700)
Problem reported by Collin Funk in:
https://lists.gnu.org/r/bug-tar/2024-07/msg00000.html
though this patch is more general than Collin’s suggestion.
* src/compare.c (diff_multivol):
* src/delete.c (move_archive):
* src/sparse.c (oldgnu_add_sparse, pax_decode_header):
* src/system.c (mtioseek):
Prefer ckd_add and ckd_mul to the intprops.h equivalents,
since stdckdint.h is now standard.

src/compare.c
src/delete.c
src/sparse.c
src/system.c

index 348554e300c46c514415b2d4c701101f90612294..4c3162d00dad6a922ea434bd99bafcbe788d23c3 100644 (file)
@@ -407,16 +407,13 @@ diff_dumpdir (struct tar_stat_info *dir)
 static void
 diff_multivol (void)
 {
-  struct stat stat_data;
-  int fd, status;
-  off_t offset;
-
   if (current_stat_info.had_trailing_slash)
     {
       diff_dir ();
       return;
     }
 
+  struct stat stat_data;
   if (!get_stat_data (current_stat_info.file_name, &stat_data))
     return;
 
@@ -427,10 +424,11 @@ diff_multivol (void)
       return;
     }
 
-  offset = OFF_FROM_HEADER (current_header->oldgnu_header.offset);
+  off_t offset = OFF_FROM_HEADER (current_header->oldgnu_header.offset);
+  off_t file_size;
   if (offset < 0
-      || INT_ADD_OVERFLOW (current_stat_info.stat.st_size, offset)
-      || stat_data.st_size != current_stat_info.stat.st_size + offset)
+      || ckd_add (&file_size, current_stat_info.stat.st_size, offset)
+      || stat_data.st_size != file_size)
     {
       report_difference (&current_stat_info, _("Size differs"));
       skip_member ();
@@ -438,7 +436,7 @@ diff_multivol (void)
     }
 
 
-  fd = openat (chdir_fd, current_stat_info.file_name, open_read_flags);
+  int fd = openat (chdir_fd, current_stat_info.file_name, open_read_flags);
 
   if (fd < 0)
     {
@@ -456,8 +454,7 @@ diff_multivol (void)
   else
     read_and_process (&current_stat_info, process_rawdata);
 
-  status = close (fd);
-  if (status != 0)
+  if (close (fd) < 0)
     close_error (current_stat_info.file_name);
 }
 
index 48b12dc3ffe86288350065224f2164e97003589e..cd32ec97a078ec264d52f31f314f90580e00f9ca 100644 (file)
@@ -52,9 +52,9 @@ move_archive (off_t count)
       idx_t short_size = position0 % record_size;
       idx_t start_offset = short_size ? record_size - short_size : 0;
       off_t increment, move_start;
-      if (INT_MULTIPLY_WRAPV (record_size, count, &increment)
-         || INT_ADD_WRAPV (position0, start_offset, &move_start)
-         || INT_ADD_WRAPV (move_start, increment, &position)
+      if (ckd_mul (&increment, record_size, count)
+         || ckd_add (&move_start, position0, start_offset)
+         || ckd_add (&position, move_start, increment)
          || position < 0)
        {
          ERROR ((0, EOVERFLOW, "lseek: %s", archive_name_array[0]));
index 7a4b8fb2d2964b4d02449ced28492783e2a377f1..0a12e3ed5a9abd827f230d48f39b66cea0c1a1dc 100644 (file)
@@ -795,9 +795,10 @@ oldgnu_add_sparse (struct tar_sparse_file *file, struct sparse *s)
     return add_finish;
   sp.offset = OFF_FROM_HEADER (s->offset);
   sp.numbytes = OFF_FROM_HEADER (s->numbytes);
+  off_t size;
   if (sp.offset < 0 || sp.numbytes < 0
-      || INT_ADD_OVERFLOW (sp.offset, sp.numbytes)
-      || file->stat_info->stat.st_size < sp.offset + sp.numbytes
+      || ckd_add (&size, sp.offset, sp.numbytes)
+      || file->stat_info->stat.st_size < size
       || file->stat_info->archive_file_size < 0)
     return add_fail;
 
@@ -1334,9 +1335,10 @@ pax_decode_header (struct tar_sparse_file *file)
            }
          sp.offset = u;
          COPY_BUF (blk,nbuf,p);
+         off_t size;
          if (!decode_num (&u, nbuf, TYPE_MAXIMUM (off_t))
-             || INT_ADD_OVERFLOW (sp.offset, u)
-             || file->stat_info->stat.st_size < sp.offset + u)
+             || ckd_add (&size, sp.offset, u)
+             || file->stat_info->stat.st_size < size)
            {
              ERROR ((0, 0, _("%s: malformed sparse archive member"),
                      file->stat_info->orig_file_name));
index ec2dd7f5ff6c9ede1a7a4cfaa14a322e6074b066..c07e2083f0cfff955dc1c04930a3393a20ea7a9b 100644 (file)
@@ -62,8 +62,8 @@ mtioseek (bool count_files, off_t count)
                         ? (count < 0 ? MTBSF : MTFSF)
                         : (count < 0 ? MTBSR : MTFSR));
       if (! (count < 0
-            ? INT_SUBTRACT_WRAPV (0, count, &operation.mt_count)
-            : INT_ADD_WRAPV (count, 0, &operation.mt_count))
+            ? ckd_sub (&operation.mt_count, 0, count)
+            : ckd_add (&operation.mt_count, count, 0))
          && (0 <= rmtioctl (archive, MTIOCTOP, &operation)
              || (errno == EIO
                  && 0 <= rmtioctl (archive, MTIOCTOP, &operation))))