From: Paul Eggert Date: Wed, 31 Jul 2024 00:59:04 +0000 (-0700) Subject: Prefer stdckdint.h to intprops.h X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9372cf08a05723b2a06efff3402077598138238;p=thirdparty%2Ftar.git Prefer stdckdint.h to intprops.h 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. --- diff --git a/src/compare.c b/src/compare.c index 348554e3..4c3162d0 100644 --- a/src/compare.c +++ b/src/compare.c @@ -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 (¤t_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 (¤t_stat_info, process_rawdata); - status = close (fd); - if (status != 0) + if (close (fd) < 0) close_error (current_stat_info.file_name); } diff --git a/src/delete.c b/src/delete.c index 48b12dc3..cd32ec97 100644 --- a/src/delete.c +++ b/src/delete.c @@ -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])); diff --git a/src/sparse.c b/src/sparse.c index 7a4b8fb2..0a12e3ed 100644 --- a/src/sparse.c +++ b/src/sparse.c @@ -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)); diff --git a/src/system.c b/src/system.c index ec2dd7f5..c07e2083 100644 --- a/src/system.c +++ b/src/system.c @@ -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))))