64 lines
1.6 KiB
Diff
64 lines
1.6 KiB
Diff
From 770ad3ecac91f59c3e3296ac63a7001630f98d86 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
|
|
Date: Mon, 22 Jan 2024 14:54:57 +0100
|
|
Subject: [PATCH] checkpolicy: check allocation and free memory on error at
|
|
type definition
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
|
|
Acked-by: James Carter <jwcart2@gmail.com>
|
|
---
|
|
policy_define.c | 23 +++++++++++++++++------
|
|
1 file changed, 17 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/policy_define.c b/policy_define.c
|
|
index 053156df..ec19da9d 100644
|
|
--- a/policy_define.c
|
|
+++ b/policy_define.c
|
|
@@ -1399,7 +1399,7 @@ int define_typeattribute(void)
|
|
return 0;
|
|
}
|
|
|
|
-static int define_typebounds_helper(char *bounds_id, char *type_id)
|
|
+static int define_typebounds_helper(const char *bounds_id, const char *type_id)
|
|
{
|
|
type_datum_t *bounds, *type;
|
|
|
|
@@ -1482,15 +1482,26 @@ int define_type(int alias)
|
|
* old name based hierarchy.
|
|
*/
|
|
if ((id = queue_remove(id_queue))) {
|
|
- char *bounds, *delim;
|
|
+ const char *delim;
|
|
+
|
|
+ if ((delim = strrchr(id, '.'))) {
|
|
+ int ret;
|
|
+ char *bounds = strdup(id);
|
|
+ if (!bounds) {
|
|
+ yyerror("out of memory");
|
|
+ free(id);
|
|
+ return -1;
|
|
+ }
|
|
|
|
- if ((delim = strrchr(id, '.'))
|
|
- && (bounds = strdup(id))) {
|
|
bounds[(size_t)(delim - id)] = '\0';
|
|
|
|
- if (define_typebounds_helper(bounds, id))
|
|
- return -1;
|
|
+ ret = define_typebounds_helper(bounds, id);
|
|
free(bounds);
|
|
+ if (ret) {
|
|
+ free(id);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
}
|
|
free(id);
|
|
}
|
|
--
|
|
2.33.0
|
|
|