libsepol/backport-libsepol-add-missing-oom-checks.patch
jinlun f442c6877c backport bugfix from upstream
(cherry picked from commit 43a82f031f3f216969ba3baa2053109752f7a311)
2023-02-22 11:42:03 +08:00

78 lines
2.2 KiB
Diff

From 0233e4f6d59a96b759e32661a20be4bbadb374a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Thu, 31 Mar 2022 16:44:52 +0200
Subject: [PATCH] libsepol: add missing oom checks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Check return values of memory allocation functions and propagate their
failure.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
---
src/kernel_to_cil.c | 5 +++++
src/module_to_cil.c | 7 +++++++
src/policydb.c | 3 ++-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/kernel_to_cil.c b/src/kernel_to_cil.c
index d4dee8d..ef6161c 100644
--- a/libsepol/src/kernel_to_cil.c
+++ b/libsepol/src/kernel_to_cil.c
@@ -555,6 +555,11 @@ static int write_sids_to_cil(FILE *out, const char *const *sid_to_str,
} else {
snprintf(unknown, 18, "%s%u", "UNKNOWN", i);
sid = strdup(unknown);
+ if (!sid) {
+ sepol_log_err("Out of memory");
+ rc = -1;
+ goto exit;
+ }
}
rc = strs_add_at_index(strs, sid, i);
if (rc != 0) {
diff --git a/src/module_to_cil.c b/src/module_to_cil.c
index 3e17018..5027fb7 100644
--- a/libsepol/src/module_to_cil.c
+++ b/libsepol/src/module_to_cil.c
@@ -391,6 +391,8 @@ static int typealias_list_create(struct policydb *pdb)
}
typealias_lists = calloc(max_decl_id + 1, sizeof(*typealias_lists));
+ if (!typealias_lists)
+ goto exit;
typealias_lists_len = max_decl_id + 1;
rc = hashtab_map(pdb->p_types.table, typealiases_gather_map, pdb);
@@ -2551,6 +2553,11 @@ static int ocontext_isid_to_cil(struct policydb *pdb, const char *const *sid_to_
goto exit;
}
item->sid_key = strdup(sid);
+ if (!item->sid_key) {
+ log_err("Out of memory");
+ rc = -1;
+ goto exit;
+ }
item->next = head;
head = item;
}
diff --git a/src/policydb.c b/src/policydb.c
index 3992ea5..982bc23 100644
--- a/libsepol/src/policydb.c
+++ b/libsepol/src/policydb.c
@@ -1248,7 +1248,8 @@ int policydb_index_others(sepol_handle_t * handle,
if (!p->type_val_to_struct)
return -1;
- cond_init_bool_indexes(p);
+ if (cond_init_bool_indexes(p))
+ return -1;
for (i = SYM_ROLES; i < SYM_NUM; i++) {
free(p->sym_val_to_name[i]);
--
2.27.0