diff options
author | Tim Kientzle <kientzle@FreeBSD.org> | 2007-02-14 08:16:08 +0000 |
---|---|---|
committer | Tim Kientzle <kientzle@FreeBSD.org> | 2007-02-14 08:16:08 +0000 |
commit | effb1b7fcba84c9a651018587f398965ab460f7d (patch) | |
tree | f116053195ae3958e83f9d7a9ed5839466a36be5 /usr.bin/tar | |
parent | 0411582e87e1f934ccad00d89017fa53e0b48139 (diff) | |
download | src-effb1b7fcba84c9a651018587f398965ab460f7d.tar.gz src-effb1b7fcba84c9a651018587f398965ab460f7d.zip |
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.
Notes
Notes:
svn path=/head/; revision=166702
Diffstat (limited to 'usr.bin/tar')
-rw-r--r-- | usr.bin/tar/write.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index 09016ddc76a5..d7fbcfb8b15f 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; |