From 4e05e478eaae9dfbe55a9efc34a7a8b10bfd88e3 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Sun, 5 Mar 2023 10:25:16 +0900 Subject: [PATCH] Fix potential NULL pointer dereference in ITS code Reported by Shashank in: and . * gettext-tools/src/locating-rule.c (get_attribute): Check return value of xmlGetProp. (document_locating_rule_match): Check return value of xmlDocGetRootElement. (locating_rule_list_add_from_file): Likewise. Signed-off-by: Daiki Ueno --- gettext-tools/src/locating-rule.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gettext-tools/src/locating-rule.c b/gettext-tools/src/locating-rule.c index baa1e0ef5..0b7777e34 100644 --- a/gettext-tools/src/locating-rule.c +++ b/gettext-tools/src/locating-rule.c @@ -90,6 +90,12 @@ get_attribute (xmlNode *node, const char *attr) char *result; value = xmlGetProp (node, BAD_CAST attr); + if (!value) + { + error (0, 0, _("cannot find attribute %s on %s"), attr, node->name); + return NULL; + } + result = xstrdup ((const char *) value); xmlFree (value); @@ -103,6 +109,13 @@ document_locating_rule_match (struct document_locating_rule_ty *rule, xmlNode *root; root = xmlDocGetRootElement (doc); + if (!root) + { + error (0, 0, _("cannot locate root element")); + xmlFreeDoc (doc); + return NULL; + } + if (rule->ns != NULL) { if (root->ns == NULL @@ -311,6 +324,13 @@ locating_rule_list_add_from_file (struct locating_rule_list_ty *rules, } root = xmlDocGetRootElement (doc); + if (!root) + { + error (0, 0, _("cannot locate root element")); + xmlFreeDoc (doc); + return false; + } + if (!(xmlStrEqual (root->name, BAD_CAST "locatingRules") #if 0 && root->ns -- 2.47.3