All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] libselinux: do not dereference a NULL pointer when calloc() fails
@ 2017-04-07 20:44 Nicolas Iooss
  2017-04-07 20:44 ` [PATCH 2/6] libsemanage: drop checks on semanage_module_info_destroy() value Nicolas Iooss
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Nicolas Iooss @ 2017-04-07 20:44 UTC (permalink / raw)
  To: selinux

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 <nicolas.iooss@m4x.org>
---
 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 60639cfcfb74..3300ddc0ab31 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;
 }
 
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-04-11 18:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-07 20:44 [PATCH 1/6] libselinux: do not dereference a NULL pointer when calloc() fails Nicolas Iooss
2017-04-07 20:44 ` [PATCH 2/6] libsemanage: drop checks on semanage_module_info_destroy() value Nicolas Iooss
2017-04-11 18:35   ` Stephen Smalley
2017-04-07 20:44 ` [PATCH 3/6] libselinux: make process_boolean() fail on invalid lines Nicolas Iooss
2017-04-11 18:37   ` Stephen Smalley
2017-04-07 20:44 ` [PATCH 4/6] libselinux: ensure that 4 columns are read from /proc/mounts Nicolas Iooss
2017-04-07 20:44 ` [PATCH 5/6] libsepol: refuse to load policies with no block Nicolas Iooss
2017-04-07 20:44 ` [PATCH 6/6] libsepol: do not wrap integers when checking bound Nicolas Iooss
2017-04-11 18:38   ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.