diff mbox series

[18/47] libsemanage: fix asprintf error branch

Message ID 20241111141706.38039-18-cgoettsche@seltendoof.de (mailing list archive)
State New
Delegated to: Petr Lautrbach
Headers show
Series [01/47] libsemanage: white space cleanup | expand

Commit Message

Christian Göttsche Nov. 11, 2024, 2:16 p.m. UTC
From: Christian Göttsche <cgzones@googlemail.com>

The content of the first argument after a failure of asprintf(3) is
undefined and must not be used.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsemanage/src/boolean_record.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libsemanage/src/boolean_record.c b/libsemanage/src/boolean_record.c
index 40dc6545..7878b04d 100644
--- a/libsemanage/src/boolean_record.c
+++ b/libsemanage/src/boolean_record.c
@@ -107,8 +107,10 @@  int semanage_bool_set_name(semanage_handle_t * handle,
 	end++;
 	*end = '\0';
 	rc = asprintf(&newroot, "%s%s%s", prefix, olddir, storename);
-	if (rc < 0)
+	if (rc < 0) {
+		newroot = NULL;
 		goto out;
+	}
 
 	if (strcmp(oldroot, newroot)) {
 		rc = selinux_set_policy_root(newroot);