diff options
author | cperciva <cperciva@FreeBSD.org> | 2008-05-23 05:01:29 +0000 |
---|---|---|
committer | cperciva <cperciva@FreeBSD.org> | 2008-05-23 05:01:29 +0000 |
commit | 8ae6743fcd2d34f030e006f8b78ec059408646b1 (patch) | |
tree | bb7415e382f20a44bf7771c096d9441d02582068 /lib | |
parent | edcc4efbbbba8f8af9957735bf0333cf36665ced (diff) | |
download | FreeBSD-src-8ae6743fcd2d34f030e006f8b78ec059408646b1.zip FreeBSD-src-8ae6743fcd2d34f030e006f8b78ec059408646b1.tar.gz |
Check that lseek(2) succeeds and puts us where we expect. [1]
While we're here, fix a long-standing bug in the handling of write(2)
errors: The API changed from "return # of bytes written" to "return
status code" almost 4 years ago, so instead of returning (-1) we need
to return ARCHIVE_FATAL.
Found by: Coverity Prevent [1]
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libarchive/archive_read_data_into_fd.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/libarchive/archive_read_data_into_fd.c b/lib/libarchive/archive_read_data_into_fd.c index cc15a9c..b2421bb 100644 --- a/lib/libarchive/archive_read_data_into_fd.c +++ b/lib/libarchive/archive_read_data_into_fd.c @@ -64,8 +64,12 @@ archive_read_data_into_fd(struct archive *a, int fd) ARCHIVE_OK) { const char *p = buff; if (offset > output_offset) { - lseek(fd, offset - output_offset, SEEK_CUR); - output_offset = offset; + output_offset = lseek(fd, + offset - output_offset, SEEK_CUR); + if (output_offset != offset) { + archive_set_error(a, errno, "Seek error"); + return (ARCHIVE_FATAL); + } } while (size > 0) { bytes_to_write = size; @@ -74,7 +78,7 @@ archive_read_data_into_fd(struct archive *a, int fd) bytes_written = write(fd, p, bytes_to_write); if (bytes_written < 0) { archive_set_error(a, errno, "Write error"); - return (-1); + return (ARCHIVE_FATAL); } output_offset += bytes_written; total_written += bytes_written; |