[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 6/9] block/file-posix: Fix fully preallocated truncat
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 6/9] block/file-posix: Fix fully preallocated truncate |
Date: |
Tue, 3 Apr 2018 18:33:57 +0200 |
From: Max Reitz <address@hidden>
Storing the lseek() result in an int results in it overflowing when the
file is at least 2 GB big. Then, we have a 50 % chance of the result
being "negative" and thus thinking an error occurred when actually
everything went just fine.
So we should use the correct type for storing the result: off_t.
Reported-by: Daniel P. Berrange <address@hidden>
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1549231
Cc: address@hidden
Signed-off-by: Max Reitz <address@hidden>
Message-id: address@hidden
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
block/file-posix.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index a2f6d8a8c8..3794c0007a 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1701,6 +1701,7 @@ static int raw_regular_truncate(int fd, int64_t offset,
PreallocMode prealloc,
case PREALLOC_MODE_FULL:
{
int64_t num = 0, left = offset - current_length;
+ off_t seek_result;
/*
* Knowing the final size from the beginning could allow the file
@@ -1715,8 +1716,8 @@ static int raw_regular_truncate(int fd, int64_t offset,
PreallocMode prealloc,
buf = g_malloc0(65536);
- result = lseek(fd, current_length, SEEK_SET);
- if (result < 0) {
+ seek_result = lseek(fd, current_length, SEEK_SET);
+ if (seek_result < 0) {
result = -errno;
error_setg_errno(errp, -result,
"Failed to seek to the old end of file");
--
2.13.6
- [Qemu-devel] [PULL 0/9] Block layer patches for 2.12.0-rc2, Kevin Wolf, 2018/04/03
- [Qemu-devel] [PULL 1/9] gluster: Fix blockdev-add with server.N.type=unix, Kevin Wolf, 2018/04/03
- [Qemu-devel] [PULL 3/9] iotests: Update 051 and 186 after commit 1454509726719e0933c, Kevin Wolf, 2018/04/03
- [Qemu-devel] [PULL 7/9] iotests: Test preallocated truncate of 2G image, Kevin Wolf, 2018/04/03
- [Qemu-devel] [PULL 5/9] iotests: fix 208 for luks format, Kevin Wolf, 2018/04/03
- [Qemu-devel] [PULL 4/9] iotests: Update 186 after commit ac64273c66ab136c44043259162, Kevin Wolf, 2018/04/03
- [Qemu-devel] [PULL 8/9] qemu-iotests: Use ppc64 qemu_arch on ppc64le host, Kevin Wolf, 2018/04/03
- [Qemu-devel] [PULL 2/9] block: handle invalid lseek returns gracefully, Kevin Wolf, 2018/04/03
- [Qemu-devel] [PULL 6/9] block/file-posix: Fix fully preallocated truncate,
Kevin Wolf <=
- [Qemu-devel] [PULL 9/9] iotests: Test abnormally large size in compressed cluster descriptor, Kevin Wolf, 2018/04/03
- Re: [Qemu-devel] [PULL 0/9] Block layer patches for 2.12.0-rc2, Peter Maydell, 2018/04/04