semodule_link: avoid NULL dereference on OOM

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: 63e798a203 ("semodule_link: update")

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Christian Göttsche 2023-11-09 14:53:11 +01:00 committed by James Carter
parent de491fda3d
commit 8547846ecd

View File

@ -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;