commit:     260627000f51e32ebc0a3b049b912664a1a3dd5f
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue May 13 00:14:27 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue May 13 00:15:24 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=26062700

sys-devel/dwz: fix crash on lapack

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

 sys-devel/dwz/dwz-0.15-r5.ebuild                | 75 +++++++++++++++++++++++++
 sys-devel/dwz/files/dwz-0.15-lapack-crash.patch | 63 +++++++++++++++++++++
 2 files changed, 138 insertions(+)

diff --git a/sys-devel/dwz/dwz-0.15-r5.ebuild b/sys-devel/dwz/dwz-0.15-r5.ebuild
new file mode 100644
index 000000000000..6060be3ab13a
--- /dev/null
+++ b/sys-devel/dwz/dwz-0.15-r5.ebuild
@@ -0,0 +1,75 @@
+# Copyright 1999-2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+inherit toolchain-funcs
+
+DESCRIPTION="DWARF optimization and duplicate removal tool"
+HOMEPAGE="https://sourceware.org/dwz";
+if [[ ${PV} == 9999 ]] ; then
+       EGIT_REPO_URI="https://sourceware.org/git/dwz.git";
+       inherit git-r3
+else
+       SRC_URI="https://sourceware.org/ftp/dwz/releases/${P}.tar.xz";
+       S="${WORKDIR}/${PN}"
+
+       #KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~riscv ~sparc ~x86"
+       KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~loong ~ppc ~ppc64 ~riscv ~sparc 
~x86"
+fi
+
+LICENSE="GPL-2+ GPL-3+"
+SLOT="0"
+IUSE="test"
+RESTRICT="!test? ( test )"
+
+RDEPEND="
+       dev-libs/elfutils
+       dev-libs/xxhash
+       elibc_musl? (
+               >=sys-libs/error-standalone-2.0
+               sys-libs/obstack-standalone
+       )
+"
+DEPEND="${RDEPEND}"
+BDEPEND="
+       test? (
+               dev-debug/gdb
+               dev-libs/elfutils[utils]
+               dev-util/dejagnu
+       )
+       virtual/pkgconfig
+"
+
+PATCHES=(
+       "${FILESDIR}"/${P}-gdb-15.patch
+       "${FILESDIR}"/${P}-readelf.patch
+       "${FILESDIR}"/${P}-lapack-crash.patch
+)
+
+src_prepare() {
+       default
+       tc-export CC
+}
+
+src_compile() {
+       export LANG=C LC_ALL=C  # grep find nothing for non-ascii locales
+
+       tc-export PKG_CONFIG
+
+       export LIBS="-lelf"
+       if use elibc_musl; then
+               export CFLAGS="${CFLAGS} $(${PKG_CONFIG} --cflags 
obstack-standalone error-standalone)"
+               export LIBS="${LIBS} $(${PKG_CONFIG} --libs obstack-standalone 
error-standalone)"
+       fi
+
+       emake CFLAGS="${CFLAGS}" LIBS="${LIBS}" srcdir="${S}"
+}
+
+src_test() {
+       emake CFLAGS="${CFLAGS}" LIBS="${LIBS}" srcdir="${S}" check
+}
+
+src_install() {
+       emake DESTDIR="${D}" CFLAGS="${CFLAGS}" LIBS="${LIBS}" srcdir="${S}" 
install
+}

diff --git a/sys-devel/dwz/files/dwz-0.15-lapack-crash.patch 
b/sys-devel/dwz/files/dwz-0.15-lapack-crash.patch
new file mode 100644
index 000000000000..b587aa622b22
--- /dev/null
+++ b/sys-devel/dwz/files/dwz-0.15-lapack-crash.patch
@@ -0,0 +1,63 @@
+https://sourceware.org/PR32934
+https://sourceware.org/git/?p=dwz.git;a=commit;h=ed021b829933e5f9ee90587196ba941c30ac832a
+
+From ed021b829933e5f9ee90587196ba941c30ac832a Mon Sep 17 00:00:00 2001
+From: Tom de Vries <[email protected]>
+Date: Mon, 12 May 2025 14:01:40 +0200
+Subject: [PATCH] Fix double free in compute_abbrevs
+
+PR32934 reports an abort in obstack_free after a double free.
+
+The relevant code is in compute_abbrevs:
+...
+  t = (struct abbrev_tag *)
+      obstack_alloc (&ob2,
+                     sizeof (*t)
+                     + (max_nattr + 4) * sizeof (struct abbrev_attr)
+                     + (max_nattr + 4) * sizeof (int64_t));
+  ...
+  obstack_free (&ob2, (void *) t);
+  cuarr = (dw_cu_ref *) obstack_alloc (&ob2, ncus * sizeof (dw_cu_ref));
+  ...
+  obstack_free (&ob2, (void *) t);
+...
+
+The following happens:
+- t is allocated
+- t is freed
+- cuarr is allocated
+- t is freed.
+
+Usually, cuarr == t, so effectively cuarr is freed.
+
+But in the case of the PR, cuarr != t, so t is freed twice, triggering the
+abort.
+
+Fix this by freeing cuarr instead.
+
+Tested on x86_64-linux.
+
+Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32934
+
+2025-05-12  Tom de Vries  <[email protected]>
+
+       * dwz.c (compute_abbrevs): Free cuarr instead of double-freeing t.
+---
+ dwz.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/dwz.c b/dwz.c
+index da4121f..a27eb4d 100644
+--- a/dwz.c
++++ b/dwz.c
+@@ -11813,7 +11813,7 @@ compute_abbrevs (DSO *dso)
+       }
+       obstack_free (&ob2, (void *) arr);
+     }
+-  obstack_free (&ob2, (void *) t);
++  obstack_free (&ob2, (void *) cuarr);
+   for (cu = first_cu; cu; cu = cu->cu_next)
+     {
+       struct abbrev_tag **arr;
+-- 
+2.43.5

Reply via email to