mcstrans: check memory allocations

Avoid NULL dereferences on allocation failure.

Reported by GCC analyzer.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Christian Göttsche 2024-01-05 19:35:34 +01:00 committed by James Carter
parent 99170284ef
commit 114f1bb16e

View File

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