]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix potential NULL pointer dereference in ITS code
authorDaiki Ueno <ueno@gnu.org>
Sun, 5 Mar 2023 01:25:16 +0000 (10:25 +0900)
committerDaiki Ueno <ueno@gnu.org>
Sun, 5 Mar 2023 01:31:25 +0000 (10:31 +0900)
Reported by Shashank in: <https://savannah.gnu.org/bugs/?63529> and
<https://savannah.gnu.org/bugs/?63530>.

* 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 <ueno@gnu.org>
gettext-tools/src/locating-rule.c

index baa1e0ef55eaef55f1a1a6d647a2a5f1ce00a7be..0b7777e34505786036e1a12f93bcea8ff7f9432f 100644 (file)
@@ -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