From d180e2b3d4798864aa954ba29ffb221b9ad08cd4 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sat, 6 Feb 2010 20:41:25 +0000 Subject: [PATCH] Fill in some missing error handling, be a little more careful about error reporting, prefer int64_t to off_t. --- usr.bin/tar/read.c | 2 +- usr.bin/tar/write.c | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c index 16334d1691c4..def0953033ae 100644 --- a/usr.bin/tar/read.c +++ b/usr.bin/tar/read.c @@ -154,7 +154,7 @@ read_archive(struct bsdtar *bsdtar, char mode) archive_read_support_compression_all(a); archive_read_support_format_all(a); if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options)) - bsdtar_errc(1, 0, archive_error_string(a)); + bsdtar_errc(1, 0, "%s", archive_error_string(a)); if (archive_read_open_file(a, bsdtar->filename, bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block : DEFAULT_BYTES_PER_BLOCK)) diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index 2ac519f426d9..864bfd19f62d 100644 --- a/usr.bin/tar/write.c +++ b/usr.bin/tar/write.c @@ -215,9 +215,9 @@ tar_mode_c(struct bsdtar *bsdtar) } if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) - bsdtar_errc(1, 0, archive_error_string(a)); + bsdtar_errc(1, 0, "%s", archive_error_string(a)); if (ARCHIVE_OK != archive_write_open_file(a, bsdtar->filename)) - bsdtar_errc(1, 0, archive_error_string(a)); + bsdtar_errc(1, 0, "%s", archive_error_string(a)); write_archive(a, bsdtar); } @@ -228,7 +228,7 @@ tar_mode_c(struct bsdtar *bsdtar) void tar_mode_r(struct bsdtar *bsdtar) { - off_t end_offset; + int64_t end_offset; int format; struct archive *a; struct archive_entry *entry; @@ -302,11 +302,12 @@ tar_mode_r(struct bsdtar *bsdtar) format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; archive_write_set_format(a, format); } - lseek(bsdtar->fd, end_offset, SEEK_SET); /* XXX check return val XXX */ + if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0) + bsdtar_errc(1, errno, "Could not seek to archive end"); if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) - bsdtar_errc(1, 0, archive_error_string(a)); + bsdtar_errc(1, 0, "%s", archive_error_string(a)); if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd)) - bsdtar_errc(1, 0, archive_error_string(a)); + bsdtar_errc(1, 0, "%s", archive_error_string(a)); write_archive(a, bsdtar); /* XXX check return val XXX */ @@ -317,7 +318,7 @@ tar_mode_r(struct bsdtar *bsdtar) void tar_mode_u(struct bsdtar *bsdtar) { - off_t end_offset; + int64_t end_offset; struct archive *a; struct archive_entry *entry; int format; @@ -384,12 +385,12 @@ tar_mode_u(struct bsdtar *bsdtar) bsdtar->bytes_per_block); } else archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK); - lseek(bsdtar->fd, end_offset, SEEK_SET); - ftruncate(bsdtar->fd, end_offset); + if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0) + bsdtar_errc(1, errno, "Could not seek to archive end"); if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) - bsdtar_errc(1, 0, archive_error_string(a)); + bsdtar_errc(1, 0, "%s", archive_error_string(a)); if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd)) - bsdtar_errc(1, 0, archive_error_string(a)); + bsdtar_errc(1, 0, "%s", archive_error_string(a)); write_archive(a, bsdtar); @@ -438,7 +439,7 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) bsdtar->argv++; arg = *bsdtar->argv; if (arg == NULL) { - bsdtar_warnc(1, 0, + bsdtar_warnc(0, "%s", "Missing argument for -C"); bsdtar->return_value = 1; goto cleanup; @@ -558,7 +559,7 @@ append_archive_filename(struct bsdtar *bsdtar, struct archive *a, rc = append_archive(bsdtar, a, ina); - if (archive_errno(ina)) { + if (rc != ARCHIVE_OK) { bsdtar_warnc(0, "Error reading archive %s: %s", filename, archive_error_string(ina)); bsdtar->return_value = 1; @@ -623,7 +624,7 @@ copy_file_data(struct bsdtar *bsdtar, struct archive *a, { ssize_t bytes_read; ssize_t bytes_written; - off_t progress = 0; + int64_t progress = 0; bytes_read = archive_read_data(ina, bsdtar->buff, FILEDATABUFLEN); while (bytes_read > 0) { @@ -771,7 +772,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) entry, -1, st); if (r != ARCHIVE_OK) bsdtar_warnc(archive_errno(bsdtar->diskreader), - archive_error_string(bsdtar->diskreader)); + "%s", archive_error_string(bsdtar->diskreader)); if (r < ARCHIVE_WARN) continue; @@ -935,7 +936,7 @@ write_file_data(struct bsdtar *bsdtar, struct archive *a, { ssize_t bytes_read; ssize_t bytes_written; - off_t progress = 0; + int64_t progress = 0; bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN); while (bytes_read > 0) {