Blame SOURCES/0081-restripe-fix-ignoring-return-value-of-read-and-lseek.patch

790dca
From d92cee7b374db9944b63bdd6c1784a2dd90ee9ca Mon Sep 17 00:00:00 2001
790dca
From: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
790dca
Date: Mon, 18 May 2020 23:53:36 +0200
790dca
Subject: [PATCH 081/108] =?UTF-8?q?restripe:=20fix=20ignoring=20return=20v?=
790dca
 =?UTF-8?q?alue=20of=20=E2=80=98read=E2=80=99=20and=20lseek?=
790dca
MIME-Version: 1.0
790dca
Content-Type: text/plain; charset=UTF-8
790dca
Content-Transfer-Encoding: 8bit
790dca
790dca
Got below error when run "make everything".
790dca
790dca
restripe.c: In function ‘test_stripes’:
790dca
restripe.c:870:4: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
790dca
    read(source[i], stripes[i], chunk_size);
790dca
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
790dca
790dca
Fix it by check the return value of ‘read’, and free memory
790dca
in the failure case.
790dca
790dca
And check the return value of lseek as well per Jes's comment.
790dca
790dca
Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
790dca
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
790dca
---
790dca
 restripe.c | 12 ++++++++++--
790dca
 1 file changed, 10 insertions(+), 2 deletions(-)
790dca
790dca
diff --git a/restripe.c b/restripe.c
790dca
index 31b07e8..86e1d00 100644
790dca
--- a/restripe.c
790dca
+++ b/restripe.c
790dca
@@ -866,8 +866,16 @@ int test_stripes(int *source, unsigned long long *offsets,
790dca
 		int disk;
790dca
 
790dca
 		for (i = 0 ; i < raid_disks ; i++) {
790dca
-			lseek64(source[i], offsets[i]+start, 0);
790dca
-			read(source[i], stripes[i], chunk_size);
790dca
+			if ((lseek64(source[i], offsets[i]+start, 0) < 0) ||
790dca
+			    (read(source[i], stripes[i], chunk_size) !=
790dca
+			     chunk_size)) {
790dca
+				free(q);
790dca
+				free(p);
790dca
+				free(blocks);
790dca
+				free(stripes);
790dca
+				free(stripe_buf);
790dca
+				return -1;
790dca
+			}
790dca
 		}
790dca
 		for (i = 0 ; i < data_disks ; i++) {
790dca
 			int disk = geo_map(i, start/chunk_size, raid_disks,
790dca
-- 
790dca
2.7.5
790dca