From 1f080ffd7ab24b0ad2b46f79db63d62c2ae2747c Mon Sep 17 00:00:00 2001 From: Vit Mojzis Date: Fri, 19 Jul 2024 18:17:13 +0200 Subject: [PATCH] libsepol/sepol_compute_sid: Do not destroy uninitialized context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid context_destroy() on "newcontext" before context_init() is called. Fixes: libsepol-3.6/src/services.c:1335: var_decl: Declaring variable "newcontext" without initializer. libsepol-3.6/src/services.c:1462: uninit_use_in_call: Using uninitialized value "newcontext.range.level[0].cat.node" when calling "context_destroy". \# 1460| rc = sepol_sidtab_context_to_sid(sidtab, &newcontext, out_sid); \# 1461| out: \# 1462|-> context_destroy(&newcontext); \# 1463| return rc; \# 1464| } Signed-off-by: Vit Mojzis Reviewed-by: Christian Göttsche Acked-by: Stephen Smalley --- libsepol/src/services.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libsepol/src/services.c b/libsepol/src/services.c index 36e2368f6..f3231f178 100644 --- a/libsepol/src/services.c +++ b/libsepol/src/services.c @@ -1362,14 +1362,12 @@ static int sepol_compute_sid(sepol_security_id_t ssid, scontext = sepol_sidtab_search(sidtab, ssid); if (!scontext) { ERR(NULL, "unrecognized SID %d", ssid); - rc = -EINVAL; - goto out; + return -EINVAL; } tcontext = sepol_sidtab_search(sidtab, tsid); if (!tcontext) { ERR(NULL, "unrecognized SID %d", tsid); - rc = -EINVAL; - goto out; + return -EINVAL; } if (tclass && tclass <= policydb->p_classes.nprim)