From 55b5b7a646589f2eb3b77ab4f58ccc1d2b010727 Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Fri, 7 Apr 2017 22:44:26 +0200 Subject: [PATCH] libselinux: do not dereference a NULL pointer when calloc() fails selabel_is_digest_set() contains the following code: digest = calloc(1, sizeof(*digest)); if (!digest) goto err; /* ... */ err: free(digest->digest); If calloc() failed, digest is NULL but is dereferenced when the execution jumps to label err. Check that digest is not NULL before freeing its fields. This issue has been found using clang's static analyzer. Signed-off-by: Nicolas Iooss --- libselinux/src/label.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libselinux/src/label.c b/libselinux/src/label.c index 60639cfc..3300ddc0 100644 --- a/libselinux/src/label.c +++ b/libselinux/src/label.c @@ -191,9 +191,11 @@ static inline struct selabel_digest *selabel_is_digest_set return NULL; err: - free(digest->digest); - free(digest->specfile_list); - free(digest); + if (digest) { + free(digest->digest); + free(digest->specfile_list); + free(digest); + } return NULL; }