[PATCH 1/5] semodule_link: avoid NULL dereference on OOM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <cgzones@xxxxxxxxxxxxxx>
---
 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;
-- 
2.42.0




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux