]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libxml: Fix an ISO C undefined behaviour. master
authorBruno Haible <bruno@clisp.org>
Wed, 29 Jul 2026 22:57:30 +0000 (00:57 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 29 Jul 2026 22:58:22 +0000 (00:58 +0200)
ISO C 23 ยง 6.5.7.(10) has requirements for pointer subtraction.

Found by use of Fil-C.

* gnulib-local/lib/libxml/parser.c (xmlParseStartTag2): Avoid invalid pointer
subtraction.

gnulib-local/lib/libxml/parser.c

index d485a58b8ea3dc21a44418c7a80ef8fd2b369c2f..72190427453b4cc2ad1b09fa32e9bfe0ed1fbbbc 100644 (file)
@@ -1,5 +1,5 @@
 /* libxml2 - Library for parsing XML documents
- * Copyright (C) 2006-2019 Free Software Foundation, Inc.
+ * Copyright (C) 2006-2026 Free Software Foundation, Inc.
  *
  * This file is not part of the GNU gettext program, but is used with
  * GNU gettext.
@@ -9460,12 +9460,11 @@ next_attr:
         if (atts[i+2] != NULL) {
             /*
              * Arithmetic on dangling pointers is technically undefined
-             * behavior, but well...
+             * behavior. Therefore:
              */
-            ptrdiff_t offset = ctxt->input->base - atts[i+2];
+            atts[i+3] = ctxt->input->base + (atts[i+3] - atts[i+2]); /* value */
+            atts[i+4] = ctxt->input->base + (atts[i+4] - atts[i+2]); /* valuend */
             atts[i+2]  = NULL;    /* Reset repurposed namespace URI */
-            atts[i+3] += offset;  /* value */
-            atts[i+4] += offset;  /* valuend */
         }
     }