From 8547846ecdb75ee418dd3fdc73f27701969de00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 9 Nov 2023 14:53:11 +0100 Subject: [PATCH] semodule_link: avoid NULL dereference on OOM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case the initial calloc(3) call fails the variable mods is still NULL while its size hint num_mods is set. Reported by Clang Analyzer: semodule_link.c:182:29: warning: Array access (from variable 'mods') results in a null pointer dereference [core.NullDereference] 182 | sepol_module_package_free(mods[i]); | ^~~~~~~ Fixes: 63e798a2034a ("semodule_link: update") Signed-off-by: Christian Göttsche Acked-by: James Carter --- semodule-utils/semodule_link/semodule_link.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/semodule-utils/semodule_link/semodule_link.c b/semodule-utils/semodule_link/semodule_link.c index 0f157bd9..58fca34d 100644 --- a/semodule-utils/semodule_link/semodule_link.c +++ b/semodule-utils/semodule_link/semodule_link.c @@ -178,9 +178,11 @@ failure: ret = EXIT_FAILURE; cleanup: - for (i = 0; i < num_mods; i++) - sepol_module_package_free(mods[i]); - free(mods); + if (mods) { + for (i = 0; i < num_mods; i++) + sepol_module_package_free(mods[i]); + free(mods); + } sepol_module_package_free(base); return ret;