Blame SOURCES/0002.patch

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