[PATCH 4/4] mcstrans: check memory allocations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Avoid NULL dereferences on allocation failure.

Reported by GCC analyzer.

Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux