commit:     9260b00ec90d1eae769780bb2c81382ef34ce938
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sun Aug  4 08:48:02 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Aug  4 08:48:02 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9260b00e

app-misc/scrub: backport UB fixes

In particular -Wmaybe-uninitialized.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 app-misc/scrub/files/scrub-2.6.1-ub-fixes.patch | 44 +++++++++++++++++++++++++
 app-misc/scrub/scrub-2.6.1-r2.ebuild            | 19 +++++++++++
 2 files changed, 63 insertions(+)

diff --git a/app-misc/scrub/files/scrub-2.6.1-ub-fixes.patch 
b/app-misc/scrub/files/scrub-2.6.1-ub-fixes.patch
new file mode 100644
index 000000000000..db18d69df103
--- /dev/null
+++ b/app-misc/scrub/files/scrub-2.6.1-ub-fixes.patch
@@ -0,0 +1,44 @@
+https://github.com/chaos/scrub/commit/9c9b3f28439835f44329228e2435f3f89e7dcee1
+
+From 9c9b3f28439835f44329228e2435f3f89e7dcee1 Mon Sep 17 00:00:00 2001
+From: Sergio Correia <[email protected]>
+Date: Wed, 17 Mar 2021 08:08:07 -0300
+Subject: [PATCH] Minor fixes to keep clang static analyzer happy
+
+- Initialize `written' and `checked' in scrub()
+- Initialize `mp->thd' before using it in refill_init()
+- Do not assign return of read_all() to `n', if we do not read this
+  value, in writesig()
+--- a/src/fillfile.c
++++ b/src/fillfile.c
+@@ -122,6 +122,7 @@ refill_init(struct memstruct **mpp, refill_t refill, int 
memsize)
+     }
+     mp->size = memsize;
+     mp->refill = refill;
++    mp->thd = 0;
+ #if WITH_PTHREADS
+     if (!no_threads) {
+         if ((mp->err = pthread_create(&mp->thd, NULL, refill_thread, mp))) {
+--- a/src/scrub.c
++++ b/src/scrub.c
+@@ -445,7 +445,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int 
bufsize,
+     prog_t p;
+     char sizestr[80];
+     bool isfull = false;
+-    off_t written, checked;
++    off_t written = (off_t)-1, checked = (off_t)-1;
+     int pcol = progress_col(seq);
+ 
+     if (!(buf = alloc_buffer(bufsize))) {
+--- a/src/sig.c
++++ b/src/sig.c
+@@ -74,7 +74,7 @@ writesig(char *path)
+         goto nomem;
+     if ((fd = open(path, O_RDWR)) < 0)
+         goto error;
+-    if ((n = read_all(fd, buf, blocksize)) < 0)
++    if (read_all(fd, buf, blocksize) < 0)
+         goto error;
+     memcpy(buf, SCRUB_MAGIC, sizeof(SCRUB_MAGIC));
+     if (lseek(fd, 0, SEEK_SET) < 0)
+

diff --git a/app-misc/scrub/scrub-2.6.1-r2.ebuild 
b/app-misc/scrub/scrub-2.6.1-r2.ebuild
new file mode 100644
index 000000000000..f4dfa6ae1f8f
--- /dev/null
+++ b/app-misc/scrub/scrub-2.6.1-r2.ebuild
@@ -0,0 +1,19 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DESCRIPTION="Overwrite files with iterative patterns"
+HOMEPAGE="https://github.com/chaos/scrub";
+SRC_URI="https://github.com/chaos/${PN}/releases/download/${PV}/${P}.tar.gz";
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~riscv ~sparc ~x86"
+
+PATCHES=(
+       "${FILESDIR}"/${P}-implicit-function-declaration-test.patch
+       "${FILESDIR}"/${PN}-2.6.1-bashism-tests.patch
+       "${FILESDIR}"/${PN}-2.6.1-tests-block-size.patch
+       "${FILESDIR}"/${PN}-2.6.1-ub-fixes.patch
+)

Reply via email to