mirror of
https://github.com/SELinuxProject/selinux
synced 2025-01-25 06:43:40 +00:00
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:
parent
99170284ef
commit
114f1bb16e
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user