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.
This commit is contained in:
Paul Eggert
2024-07-30 17:59:04 -07:00
parent be1aa32c6d
commit a9372cf08a
4 changed files with 18 additions and 19 deletions

View 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);
}

View 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]));

View 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));

View 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))))