Blame SOURCES/0002.patch

7a69c6
From 88a334ac2f98affcc526e861c2ed1b8bd2c34b3c Mon Sep 17 00:00:00 2001
7a69c6
From: Pavel Reichl <preichl@redhat.com>
7a69c6
Date: Wed, 11 May 2022 23:20:43 +0200
7a69c6
Subject: [PATCH] exfatprogs: fix some minor code issues
7a69c6
7a69c6
* Add checking of function return value
7a69c6
* Fix potentially overflowing expression
7a69c6
7a69c6
Signed-off-by: Pavel Reichl <preichl@redhat.com>
7a69c6
---
7a69c6
 fsck/de_iter.c |  9 ++++++---
7a69c6
 lib/libexfat.c | 13 ++++++++++---
7a69c6
 2 files changed, 16 insertions(+), 6 deletions(-)
7a69c6
7a69c6
diff --git a/fsck/de_iter.c b/fsck/de_iter.c
7a69c6
index bc95c49..587b027 100644
7a69c6
--- a/fsck/de_iter.c
7a69c6
+++ b/fsck/de_iter.c
7a69c6
@@ -82,6 +82,9 @@ static int read_ahead_next_blocks(struct exfat_de_iter *iter,
7a69c6
 				offset >= iter->ra_begin_offset) {
7a69c6
 			ret = get_next_clus(exfat, iter->parent,
7a69c6
 					p_clus, &ra_p_clus);
7a69c6
+			if (ret)
7a69c6
+				return ret;
7a69c6
+
7a69c6
 			if (ra_p_clus == EXFAT_EOF_CLUSTER)
7a69c6
 				return -EIO;
7a69c6
 
7a69c6
@@ -172,10 +175,10 @@ static ssize_t read_block(struct exfat_de_iter *iter, unsigned int block)
7a69c6
 			ret = get_next_clus(exfat, iter->parent,
7a69c6
 					prev_desc->p_clus, &desc->p_clus);
7a69c6
 			desc->offset = 0;
7a69c6
-			if (!ret && desc->p_clus == EXFAT_EOF_CLUSTER)
7a69c6
-				return EOF;
7a69c6
-			else if (ret)
7a69c6
+			if (ret)
7a69c6
 				return ret;
7a69c6
+			else if (desc->p_clus == EXFAT_EOF_CLUSTER)
7a69c6
+				return EOF;
7a69c6
 		}
7a69c6
 	}
7a69c6
 
7a69c6
diff --git a/lib/libexfat.c b/lib/libexfat.c
7a69c6
index 42e3fdc..ee48d3a 100644
7a69c6
--- a/lib/libexfat.c
7a69c6
+++ b/lib/libexfat.c
7a69c6
@@ -470,7 +470,12 @@ int exfat_set_volume_label(struct exfat_blk_dev *bd,
7a69c6
 		exfat_err("volume entry write failed: %d\n", errno);
7a69c6
 		return -1;
7a69c6
 	}
7a69c6
-	fsync(bd->dev_fd);
7a69c6
+
7a69c6
+	if (fsync(bd->dev_fd) == -1) {
7a69c6
+		exfat_err("failed to sync volume entry: %d, %s\n", errno,
7a69c6
+			  strerror(errno));
7a69c6
+		return -1;
7a69c6
+	}
7a69c6
 
7a69c6
 	exfat_info("new label: %s\n", label_input);
7a69c6
 	return 0;
7a69c6
@@ -479,7 +484,8 @@ int exfat_set_volume_label(struct exfat_blk_dev *bd,
7a69c6
 int exfat_read_sector(struct exfat_blk_dev *bd, void *buf, unsigned int sec_off)
7a69c6
 {
7a69c6
 	int ret;
7a69c6
-	unsigned long long offset = sec_off * bd->sector_size;
7a69c6
+	unsigned long long offset =
7a69c6
+		(unsigned long long)sec_off * bd->sector_size;
7a69c6
 
7a69c6
 	ret = pread(bd->dev_fd, buf, bd->sector_size, offset);
7a69c6
 	if (ret < 0) {
7a69c6
@@ -493,7 +499,8 @@ int exfat_write_sector(struct exfat_blk_dev *bd, void *buf,
7a69c6
 		unsigned int sec_off)
7a69c6
 {
7a69c6
 	int bytes;
7a69c6
-	unsigned long long offset = sec_off * bd->sector_size;
7a69c6
+	unsigned long long offset =
7a69c6
+		(unsigned long long)sec_off * bd->sector_size;
7a69c6
 
7a69c6
 	bytes = pwrite(bd->dev_fd, buf, bd->sector_size, offset);
7a69c6
 	if (bytes != (int)bd->sector_size) {
7a69c6
-- 
7a69c6
2.35.3
7a69c6