File pacemaker#3292-0002-Low-libcrmcommon-fix-NULL-dereference-in-expand_idre.patch of Package pacemaker.38495
From c5715a0aaa8c8e4900df5292f9d0e5236cc86050 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 14 Dec 2023 15:53:41 -0600
Subject: [PATCH] Low: libcrmcommon: fix NULL dereference in expand_idref()
... detected by static analysis. Also, rename variables and reformat for
readability.
---
lib/common/xml.c | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
Index: pacemaker-2.1.5+20221208.a3f44794f/lib/common/xml.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/lib/common/xml.c
+++ pacemaker-2.1.5+20221208.a3f44794f/lib/common/xml.c
@@ -3001,34 +3001,32 @@ crm_xml_cleanup(void)
xmlNode *
expand_idref(xmlNode * input, xmlNode * top)
{
- const char *tag = NULL;
+ char *xpath = NULL;
const char *ref = NULL;
- xmlNode *result = input;
+ xmlNode *result = NULL;
- if (result == NULL) {
+ if (input == NULL) {
return NULL;
-
- } else if (top == NULL) {
- top = input;
}
- tag = crm_element_name(result);
- ref = crm_element_value(result, XML_ATTR_IDREF);
-
- if (ref != NULL) {
- char *xpath_string = crm_strdup_printf("//%s[@id='%s']", tag, ref);
+ ref = crm_element_value(input, XML_ATTR_IDREF);
+ if (ref == NULL) {
+ return input;
+ }
- result = get_xpath_object(xpath_string, top, LOG_DEBUG);
- if (result == NULL) { // Not possible with schema validation enabled
- char *nodePath = (char *)xmlGetNodePath(top);
+ if (top == NULL) {
+ top = input;
+ }
- pcmk__config_err("Ignoring invalid %s configuration: "
- XML_ATTR_IDREF " '%s' does not reference "
- "a valid object", result->name, ref);
- free(nodePath);
- }
- free(xpath_string);
+ xpath = crm_strdup_printf("//%s[@" XML_ATTR_ID "='%s']", input->name, ref);
+ result = get_xpath_object(xpath, top, LOG_DEBUG);
+ if (result == NULL) { // Not possible with schema validation enabled
+ pcmk__config_err("Ignoring invalid %s configuration: "
+ XML_ATTR_IDREF " '%s' does not reference "
+ "a valid object " CRM_XS " xpath=%s",
+ input->name, ref, xpath);
}
+ free(xpath);
return result;
}