All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [PATCH 4/4] mcstrans: check memory allocations
Date: Fri,  5 Jan 2024 19:35:34 +0100	[thread overview]
Message-ID: <20240105183534.1110639-4-cgzones@googlemail.com> (raw)
In-Reply-To: <20240105183534.1110639-1-cgzones@googlemail.com>

Avoid NULL dereferences on allocation failure.

Reported by GCC analyzer.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 mcstrans/src/mls_level.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mcstrans/src/mls_level.c b/mcstrans/src/mls_level.c
index 2017f117..2ee1a231 100644
--- a/mcstrans/src/mls_level.c
+++ b/mcstrans/src/mls_level.c
@@ -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);
-- 
2.43.0


  parent reply	other threads:[~2024-01-05 18:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-05 18:35 [PATCH 1/4] libsepol: reorder calloc(3) arguments Christian Göttsche
2024-01-05 18:35 ` [PATCH 2/4] libselinux: " Christian Göttsche
2024-01-05 18:35 ` [PATCH 3/4] sandbox: do not override warning CFLAGS Christian Göttsche
2024-01-05 18:35 ` Christian Göttsche [this message]
2024-01-05 19:56 ` [PATCH 1/4] libsepol: reorder calloc(3) arguments James Carter
2024-01-25 19:56   ` James Carter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240105183534.1110639-4-cgzones@googlemail.com \
    --to=cgzones@googlemail.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.