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

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