xml2: Replace deprecated routines with recommended ones
authorMichael Paquier <[email protected]>
Tue, 16 Apr 2024 03:26:21 +0000 (12:26 +0900)
committerMichael Paquier <[email protected]>
Tue, 16 Apr 2024 03:26:21 +0000 (12:26 +0900)
Some functions are used in the tree and are currently marked as
deprecated by upstream.  This commit refreshes the code to use the
recommended functions, leading to the following changes:
- xmlSubstituteEntitiesDefault() is gone, and needs to be replaced with
XML_PARSE_NOENT for the paths doing the parsing.
- xmlParseMemory() -> xmlReadMemory().

These functions, as well as more functions setting global states, have
been officially marked as deprecated by upstream in August 2022.  Their
replacements exist since the 2001-ish area, as far as I have checked,
so that should be safe.

This has been originally applied as 65c5864d7fac without a backpatch,
and this has come up as well when working on 400928b83.  Per request
from Tom Lane, for new buildfarm member indri that is able to see
deprecation warnings with xmlSubstituteEntitiesDefault() in 16 and older
stable branches.

Author: Dmitry Koval
Discussion: https://postgr.es/m/18274-98d16bc03520665f@postgresql.org
Discussion: https://postgr.es/m/1012981.1713222862@sss.pgh.pa.us
Bakpatch-through: 12

contrib/xml2/xpath.c
contrib/xml2/xslt_proc.c

index f44caf002008ad900d924731d8c4670e33db1daa..e297ee08b37f4731bae19818385f6113119f06b3 100644 (file)
@@ -74,8 +74,6 @@ pgxml_parser_init(PgXmlStrictness strictness)
    /* Initialize libxml */
    xmlInitParser();
 
-   xmlSubstituteEntitiesDefault(1);
-
    return xmlerrcxt;
 }
 
@@ -104,7 +102,8 @@ xml_is_well_formed(PG_FUNCTION_ARGS)
 
    PG_TRY();
    {
-       doctree = xmlParseMemory((char *) VARDATA_ANY(t), docsize);
+       doctree = xmlReadMemory((char *) VARDATA_ANY(t), docsize,
+                               NULL, NULL, XML_PARSE_NOENT);
 
        result = (doctree != NULL);
 
@@ -424,8 +423,9 @@ pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace)
 
    PG_TRY();
    {
-       workspace->doctree = xmlParseMemory((char *) VARDATA_ANY(document),
-                                           docsize);
+       workspace->doctree = xmlReadMemory((char *) VARDATA_ANY(document),
+                                          docsize, NULL, NULL,
+                                          XML_PARSE_NOENT);
        if (workspace->doctree != NULL)
        {
            workspace->ctxt = xmlXPathNewContext(workspace->doctree);
@@ -718,7 +718,9 @@ xpath_table(PG_FUNCTION_ARGS)
 
            /* Parse the document */
            if (xmldoc)
-               doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
+               doctree = xmlReadMemory(xmldoc, strlen(xmldoc),
+                                       NULL, NULL,
+                                       XML_PARSE_NOENT);
            else                /* treat NULL as not well-formed */
                doctree = NULL;
 
index 2189bca86ff63b6b544e2e9ea248d9a0a322a27a..f30a3a42c03e9328d25f44a5d87b8eee76919938 100644 (file)
@@ -85,16 +85,18 @@ xslt_process(PG_FUNCTION_ARGS)
        bool        xslt_sec_prefs_error;
 
        /* Parse document */
-       doctree = xmlParseMemory((char *) VARDATA_ANY(doct),
-                                VARSIZE_ANY_EXHDR(doct));
+       doctree = xmlReadMemory((char *) VARDATA_ANY(doct),
+                               VARSIZE_ANY_EXHDR(doct), NULL, NULL,
+                               XML_PARSE_NOENT);
 
        if (doctree == NULL)
            xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
                        "error parsing XML document");
 
        /* Same for stylesheet */
-       ssdoc = xmlParseMemory((char *) VARDATA_ANY(ssheet),
-                              VARSIZE_ANY_EXHDR(ssheet));
+       ssdoc = xmlReadMemory((char *) VARDATA_ANY(ssheet),
+                             VARSIZE_ANY_EXHDR(ssheet), NULL, NULL,
+                             XML_PARSE_NOENT);
 
        if (ssdoc == NULL)
            xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,