Backport fixes for issues found by OpenScanHub

Resolves: RHEL-7945
Signed-off-by: Pavel Reichl <preichl@redhat.com>
This commit is contained in:
Pavel Reichl 2023-12-08 17:58:28 +01:00
parent c47e67462a
commit 6c452ee46f
4 changed files with 151 additions and 1 deletions

View File

@ -1,11 +1,14 @@
Name: exfatprogs
Version: 1.2.2
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Userspace utilities for exFAT filesystems
License: GPLv2
URL: https://github.com/%{name}/%{name}
Source0: %{url}/releases/download/%{version}/%{name}-%{version}.tar.xz
Patch0: for-next-1.2.2-exfat2img-fix-Missing-Initialization.patch
Patch1: for-next-1.2.2-exfatprogs-Fix-issues-found-by-OpenScanHub-tool.patch
Patch2: for-next-1.2.2-tune-label-fix-USE_AFTER_FREE.patch
BuildRequires: autoconf
BuildRequires: automake
@ -46,6 +49,10 @@ autoreconf -vif
%{_mandir}/man8/tune.exfat.*
%changelog
* Fri Dec 08 2023 Pavel Reichl <preichl@redhat.com> - 1.2.2-2
- Backport fixes for issues found by OpenScanHub
- Related: RHEL-7945
* Mon Nov 06 2023 Pavel Reichl <preichl@redhat.com> - 1.2.2-1
- Rebase to upstream v1.2.2
- Related: RHEL-15865

View File

@ -0,0 +1,29 @@
From 79b5b71cc6a1dbc45eeb63f53a6b51aa924309c8 Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Mon, 13 Nov 2023 08:13:27 +0100
Subject: [PATCH] exfat2img: fix Missing Initialization
exfatprogs-1.2.2/exfat2img/exfat2img.c:895: uninit_use: Using uninitialized value "ret".
Signed-off-by: Pavel Reichl <preichl@redhat.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
exfat2img/exfat2img.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/exfat2img/exfat2img.c b/exfat2img/exfat2img.c
index 3f83588..f1a4ef2 100644
--- a/exfat2img/exfat2img.c
+++ b/exfat2img/exfat2img.c
@@ -762,7 +762,7 @@ static ssize_t read_stream(int fd, void *buf, size_t len)
static int restore_from_stdin(struct exfat2img *ei)
{
- int in_fd, ret;
+ int in_fd, ret = 0;
unsigned char cc;
unsigned int clu, end_clu;
unsigned int cc_clu_count;
--
2.43.0

View File

@ -0,0 +1,71 @@
From cb641bd9b81179b7f039e6d0e64cd67e7fb4e11c Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Wed, 6 Dec 2023 22:01:04 +0100
Subject: [PATCH] exfatprogs: Fix issues found by OpenScanHub tool
Fix some issues found by red hat internal OpenScanHub tool.
exfatprogs-1.2.2/exfat2img/exfat2img.c:893: check_return: Calling
"fsync" without checking return value (as is done elsewhere
6 out of 7 times).
exfatprogs-1.2.2/fsck/fsck.c:1251:2: warning[deadcode.DeadStores]:
Value stored to 'err' is never read
exfatprogs-1.2.2/lib/libexfat.c:983: returned_null: "malloc" returns
"NULL" (checked 20 out of 23 times)
Signed-off-by: Pavel Reichl <preichl@redhat.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
exfat2img/exfat2img.c | 5 ++++-
fsck/fsck.c | 1 -
lib/libexfat.c | 4 ++++
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/exfat2img/exfat2img.c b/exfat2img/exfat2img.c
index f1a4ef2..4774a56 100644
--- a/exfat2img/exfat2img.c
+++ b/exfat2img/exfat2img.c
@@ -890,7 +890,10 @@ static int restore_from_stdin(struct exfat2img *ei)
}
}
out:
- fsync(ei->out_fd);
+ if (fsync(ei->out_fd)) {
+ exfat_err("failed to fsync: %d\n", errno);
+ ret = -EIO;
+ }
exfat_free_buffer(ei->dump_bdesc, 2);
return ret;
}
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 77272aa..a5517d2 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1248,7 +1248,6 @@ static int exfat_root_dir_check(struct exfat *exfat)
err = exfat_read_volume_label(exfat);
if (err && err != EOF)
exfat_err("failed to read volume label\n");
- err = 0;
err = read_bitmap(exfat);
if (err) {
diff --git a/lib/libexfat.c b/lib/libexfat.c
index d7b8344..6ae5742 100644
--- a/lib/libexfat.c
+++ b/lib/libexfat.c
@@ -981,6 +981,10 @@ int read_boot_sect(struct exfat_blk_dev *bdev, struct pbr **bs)
unsigned int sect_size, clu_size;
pbr = malloc(sizeof(struct pbr));
+ if (!pbr) {
+ exfat_err("failed to allocate memory\n");
+ return -ENOMEM;
+ }
if (exfat_read(bdev->dev_fd, pbr, sizeof(*pbr), 0) !=
(ssize_t)sizeof(*pbr)) {
--
2.43.0

View File

@ -0,0 +1,43 @@
From 8e4f2e671a154549d07ec45cb3c9cfe31b27b27f Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Mon, 13 Nov 2023 08:37:06 +0100
Subject: [PATCH] tune: label: fix USE_AFTER_FREE
double_free: Calling free frees pointer bs which has already been freed.
if exfat_alloc_exfat fails it already frees exfat->bs via exfat_free_exfat
Signed-off-by: Pavel Reichl <preichl@redhat.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
label/label.c | 1 -
tune/tune.c | 1 -
2 files changed, 2 deletions(-)
diff --git a/label/label.c b/label/label.c
index 8cd5748..b110670 100644
--- a/label/label.c
+++ b/label/label.c
@@ -105,7 +105,6 @@ int main(int argc, char *argv[])
exfat = exfat_alloc_exfat(&bd, bs);
if (!exfat) {
- free(bs);
ret = -ENOMEM;
goto close_fd_out;
}
diff --git a/tune/tune.c b/tune/tune.c
index f883556..fdb8c94 100644
--- a/tune/tune.c
+++ b/tune/tune.c
@@ -129,7 +129,6 @@ int main(int argc, char *argv[])
exfat = exfat_alloc_exfat(&bd, bs);
if (!exfat) {
- free(bs);
ret = -ENOMEM;
goto close_fd_out;
}
--
2.43.0