libsepol: Prevent freeing unitialized value in ibendport handling

Nicolas Iooss reports:
In sepol_ibendport_key_create(), if sepol_ibendport_alloc_ibdev_name()
fails to allocate tmp_key->ibdev_name, sepol_ibendport_key_free() is
called to free the memory associated with tmp_key, which results in
free() being called on uninitialized tmp_key->ibdev_name.

This issue is reported by clang's static analyzer with the following
message:

    ibendport_record.c:115:2: warning: 1st function call argument is an
    uninitialized value
            free(key->ibdev_name);
            ^~~~~~~~~~~~~~~~~~~~~

Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
This commit is contained in:
James Carter 2018-03-07 10:01:35 -05:00
parent cf0ab12414
commit c99739a6aa

View file

@ -32,14 +32,11 @@ struct sepol_ibendport_key {
int sepol_ibendport_alloc_ibdev_name(sepol_handle_t *handle,
char **ibdev_name)
{
char *tmp_ibdev_name = NULL;
*ibdev_name = calloc(1, IB_DEVICE_NAME_MAX);
tmp_ibdev_name = calloc(1, IB_DEVICE_NAME_MAX);
if (!tmp_ibdev_name)
if (!*ibdev_name)
goto omem;
*ibdev_name = tmp_ibdev_name;
return STATUS_SUCCESS;
omem: