Blame SOURCES/cryptsetup-2.0.4-fix-write_blockwise-on-short-files.patch

7cdc99
From 63d66e7a3356da4bca77f521fd93df7cdf09b41a Mon Sep 17 00:00:00 2001
7cdc99
From: Ondrej Kozina <okozina@redhat.com>
7cdc99
Date: Tue, 19 Jun 2018 15:10:33 +0200
7cdc99
Subject: [PATCH 3/4] Fix write_blockwise on short files.
7cdc99
7cdc99
see unit test write_blockwise(length=2097153, bsize=4096), on x86
7cdc99
with original test file size=2097152.
7cdc99
7cdc99
The test is trying to write_blockwise 1 more byte than actual file
7cdc99
size.
7cdc99
---
7cdc99
 lib/utils_io.c | 8 +++-----
7cdc99
 1 file changed, 3 insertions(+), 5 deletions(-)
7cdc99
7cdc99
diff --git a/lib/utils_io.c b/lib/utils_io.c
7cdc99
index 8336b18..e0c2381 100644
7cdc99
--- a/lib/utils_io.c
7cdc99
+++ b/lib/utils_io.c
7cdc99
@@ -105,15 +105,13 @@ ssize_t write_blockwise(int fd, size_t bsize, size_t alignment,
7cdc99
 	if (hangover) {
7cdc99
 		if (posix_memalign(&hangover_buf, alignment, bsize))
7cdc99
 			goto out;
7cdc99
+		memset(hangover_buf, 0, bsize);
7cdc99
 
7cdc99
 		r = read_buffer(fd, hangover_buf, bsize);
7cdc99
-		if (r < 0 || r < (ssize_t)hangover)
7cdc99
+		if (r < 0)
7cdc99
 			goto out;
7cdc99
 
7cdc99
-		if (r < (ssize_t)bsize)
7cdc99
-			bsize = r;
7cdc99
-
7cdc99
-		if (lseek(fd, -(off_t)bsize, SEEK_CUR) < 0)
7cdc99
+		if (lseek(fd, -(off_t)r, SEEK_CUR) < 0)
7cdc99
 			goto out;
7cdc99
 
7cdc99
 		memcpy(hangover_buf, (char*)buf + solid, hangover);
7cdc99
-- 
7cdc99
1.8.3.1
7cdc99