From 31532adf8636f9795ab5f077ace4e3f00148d399 Mon Sep 17 00:00:00 2001
From: Milan Broz <gmazyland@gmail.com>
Date: Thu, 11 Oct 2018 15:39:31 +0200
Subject: [PATCH 062/324] Do not copy buffer if read fails.

---
 lib/utils_io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/utils_io.c b/lib/utils_io.c
index 1facac0..d7e1cbe 100644
--- a/lib/utils_io.c
+++ b/lib/utils_io.c
@@ -184,7 +184,8 @@ ssize_t read_blockwise(int fd, size_t bsize, size_t alignment,
 out:
 	free(hangover_buf);
 	if (buf != orig_buf) {
-		memcpy(orig_buf, buf, length);
+		if (ret == length)
+			memcpy(orig_buf, buf, length);
 		free(buf);
 	}
 	return ret;
-- 
2.19.1

