From 09b1539eed59932834d96b14f90809e600f63e67 Mon Sep 17 00:00:00 2001 From: zhangruifang2020 Date: Wed, 31 Jul 2024 11:19:15 +0800 Subject: [PATCH] backport patch form upstream (cherry picked from commit b6f633d5b7c57cbf6f78dbc1eb6ffb5998d4aeb6) --- ...ckling-UBSAN-with-memcpy-dest-NULL-0.patch | 35 +++++++++++++++++++ m4.spec | 6 +++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 backport-output-Avoid-tickling-UBSAN-with-memcpy-dest-NULL-0.patch diff --git a/backport-output-Avoid-tickling-UBSAN-with-memcpy-dest-NULL-0.patch b/backport-output-Avoid-tickling-UBSAN-with-memcpy-dest-NULL-0.patch new file mode 100644 index 0000000..ca054ea --- /dev/null +++ b/backport-output-Avoid-tickling-UBSAN-with-memcpy-dest-NULL-0.patch @@ -0,0 +1,35 @@ +From a886ea40a29a08954ff80772e267828a1d440cc9 Mon Sep 17 00:00:00 2001 +From: Eric Blake +Date: Fri, 13 Jan 2023 16:27:54 -0600 +Subject: [PATCH] output: Avoid tickling UBSAN with memcpy(dest, NULL, 0) + +Even though all libc handle it sanely (because size 0 says there is +nothing to copy), NULL is not a valid source pointer per a strict +reading of C, so UBSAN flags it: + ++output.c:511:9: runtime error: null pointer passed as argument 2, which is declared to never be null + +* src/output.c (make_room_for): Skip no-op memcpy. +Fixes: https://savannah.gnu.org/support/index.php?110809 +Reported-by: Sam James +--- + src/output.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/output.c b/src/output.c +index 956089b1..6dc8280a 100644 +--- a/src/output.c ++++ b/src/output.c +@@ -508,7 +508,8 @@ make_room_for (int length) + { + char *buffer = output_diversion->u.buffer; + output_diversion->u.buffer = xcharalloc ((size_t) wanted_size); +- memcpy (output_diversion->u.buffer, buffer, output_diversion->used); ++ if (output_diversion->used) ++ memcpy (output_diversion->u.buffer, buffer, output_diversion->used); + free (buffer); + } + +-- +2.33.0 + diff --git a/m4.spec b/m4.spec index a97394b..4dc745b 100644 --- a/m4.spec +++ b/m4.spec @@ -1,11 +1,12 @@ Name: m4 Version: 1.4.19 -Release: 3 +Release: 4 Summary: A GNU implementation of macro processor License: GPLv3+ URL: https://www.gnu.org/software/m4/ Source0: https://ftp.gnu.org/gnu/m4/%{name}-%{version}.tar.xz Patch1: 0001-Delete-test-execute_sh.patch +Patch6000: backport-output-Avoid-tickling-UBSAN-with-memcpy-dest-NULL-0.patch BuildRequires: gcc autoconf automake gettext-devel Provides: bundled(gnulib) @@ -55,6 +56,9 @@ make check %{_infodir}/m4* %changelog +* Wed Jul 31 2024 zhangruifang - 1.4.19-4 +- backport patch from upstream + * Tue Oct 25 2022 renhongxun - 1.4.19-3 - Rebuild for next release -- Gitee