summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2007-02-14 08:16:08 +0000
committerkientzle <kientzle@FreeBSD.org>2007-02-14 08:16:08 +0000
commit3cdd817959d317e0531b737d1dc174f8262c187c (patch)
treef116053195ae3958e83f9d7a9ed5839466a36be5 /usr.bin/tar
parenta47cbc19d42ab9fa6f4c7338d988e41ee433ae22 (diff)
downloadFreeBSD-src-3cdd817959d317e0531b737d1dc174f8262c187c.zip
FreeBSD-src-3cdd817959d317e0531b737d1dc174f8262c187c.tar.gz
Correctly handle writes beyond the end of the archive entry
(as determined by the initial size given to the header). Libarchive recently changed to correctly return the amount of data actually consumed in this case, which revealed this bug in bsdtar.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r--usr.bin/tar/write.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index 09016dd..d7fbcfb 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -851,11 +851,19 @@ write_file_data(struct bsdtar *bsdtar, struct archive *a, int fd)
bytes_read = read(fd, buff, sizeof(buff));
while (bytes_read > 0) {
bytes_written = archive_write_data(a, buff, bytes_read);
- if (bytes_written <= 0) {
+ if (bytes_written < 0) {
/* Write failed; this is bad */
bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
return (-1);
}
+ if (bytes_written < bytes_read) {
+ /* Write was truncated; warn but continue. */
+ bsdtar_warnc(bsdtar, 0,
+ "Truncated write; file may have grown while being archived.");
+ /* Make bsdtar return a final error because of this. */
+ bsdtar->return_value = 1;
+ return (0);
+ }
bytes_read = read(fd, buff, sizeof(buff));
}
return 0;
OpenPOWER on IntegriCloud