From 0fcb3e7ac8e761ce89fc851dd88f0927354e2345 Mon Sep 17 00:00:00 2001 From: yixiangzhike Date: Mon, 8 Jul 2024 10:47:07 +0800 Subject: [PATCH] Avoid NULL dereferences on allocation failure (cherry picked from commit 886d645564d80595ad941fe67996e260dcc4fcf5) --- ...rt-mcstrans-check-memory-allocations.patch | 44 +++++++++++++++++++ mcstrans.spec | 7 ++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 backport-mcstrans-check-memory-allocations.patch diff --git a/backport-mcstrans-check-memory-allocations.patch b/backport-mcstrans-check-memory-allocations.patch new file mode 100644 index 0000000..443f38c --- /dev/null +++ b/backport-mcstrans-check-memory-allocations.patch @@ -0,0 +1,44 @@ +From 114f1bb16ead56c06b05ac4b214e1579971c5636 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= +Date: Fri, 5 Jan 2024 19:35:34 +0100 +Subject: [PATCH] mcstrans: check memory allocations +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Avoid NULL dereferences on allocation failure. + +Reported by GCC analyzer. + +Signed-off-by: Christian Göttsche +Acked-by: James Carter +--- + mcstrans/src/mls_level.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/mcstrans/src/mls_level.c b/mcstrans/src/mls_level.c +index 2017f117..2ee1a231 100644 +--- a/mcstrans/src/mls_level.c ++++ b/mcstrans/src/mls_level.c +@@ -13,6 +13,8 @@ mls_level_t *mls_level_from_string(char *mls_context) + } + + l = (mls_level_t *) calloc(1, sizeof(mls_level_t)); ++ if (!l) ++ return NULL; + + /* Extract low sensitivity. */ + scontextp = p = mls_context; +@@ -124,6 +126,9 @@ char *mls_level_to_string(mls_level_t *l) + if (len == 0) + return NULL; + char *result = (char *)malloc(len + 1); ++ if (!result) ++ return NULL; ++ + char *p = result; + + p += sprintf(p, "s%d", l->sens); +-- +2.33.0 + diff --git a/mcstrans.spec b/mcstrans.spec index 259398a..f3d9404 100644 --- a/mcstrans.spec +++ b/mcstrans.spec @@ -1,12 +1,13 @@ Name: mcstrans Version: 3.3 -Release: 2 +Release: 3 Summary: SELinux Translation Daemon License: GPL2 URL: https://github.com/SELinuxProject/selinux/wiki Source: https://github.com/SELinuxProject/selinux/releases/download/3.3/mcstrans-3.3.tar.gz Patch0: backport-mcstrans-port-to-new-PCRE2-from-end-of-life-PCRE.patch +Patch1: backport-mcstrans-check-memory-allocations.patch BuildRequires: gcc systemd-units make BuildRequires: libselinux-devel >= %{version} @@ -41,6 +42,7 @@ mcstrans-help include help files for man page %prep %setup -q %patch0 -p2 +%patch1 -p2 %build %set_build_flags @@ -90,6 +92,9 @@ rm -rf %{buildroot}/%{_sysconfdir}/rc.d/init.d/mcstrans %{_mandir}/ru/man8/*.8.gz %changelog +* Mon Jul 8 2024 yixiangzhike - 3.3-3 +- backport upstream patch to avoid NULL dereferences + * Sun May 15 2022 yixiangzhike - 3.3-2 - port to new PCRE2 from PCRE -- Gitee