File pacemaker#3394-0004-Low-libcrmcommon-NULL-check-strdup-in-pcmk__register.patch of Package pacemaker.38495

From b5caaa97179f86d11a062f5be7f1b22ac3aeef66 Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Wed, 20 Mar 2024 20:10:24 -0700
Subject: [PATCH 4/4] Low: libcrmcommon: NULL-check strdup() in
 pcmk__register_message()

Dereferencing null pointer found by cppcheck.

Assert on failure. This is a library function but doesn't currently
return anything. Also, this would have segfaulted in the past.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
 lib/common/output.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: pacemaker-2.1.2+20211124.ada5c3b36/lib/common/output.c
===================================================================
--- pacemaker-2.1.2+20211124.ada5c3b36.orig/lib/common/output.c
+++ pacemaker-2.1.2+20211124.ada5c3b36/lib/common/output.c
@@ -145,7 +145,15 @@ pcmk__call_message(pcmk__output_t *out,
 void
 pcmk__register_message(pcmk__output_t *out, const char *message_id,
                        pcmk__message_fn_t fn) {
-    g_hash_table_replace(out->messages, strdup(message_id), fn);
+    char *message_id_copy = NULL;
+
+    message_id_copy = strdup(message_id);
+    if (message_id_copy == NULL) {
+        crm_abort(__FILE__, __func__, __LINE__, "Out of memory", FALSE, TRUE);
+        crm_exit(CRM_EX_OSERR);
+    }
+
+    g_hash_table_replace(out->messages, message_id_copy, fn);
 }
 
 void
openSUSE Build Service is sponsored by