diff options
Diffstat (limited to 'src/backend/utils/adt/xml.c')
-rw-r--r-- | src/backend/utils/adt/xml.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 1a07876cd59..41b1a5c6b0b 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -4448,7 +4448,13 @@ xpath_internal(text *xpath_expr_text, xmltype *data, ArrayType *namespaces, } } - xpathcomp = xmlXPathCompile(xpath_expr); + /* + * Note: here and elsewhere, be careful to use xmlXPathCtxtCompile not + * xmlXPathCompile. In libxml2 2.13.3 and older, the latter function + * fails to defend itself against recursion-to-stack-overflow. See + * https://gitlab.gnome.org/GNOME/libxml2/-/issues/799 + */ + xpathcomp = xmlXPathCtxtCompile(xpathctx, xpath_expr); if (xpathcomp == NULL || xmlerrcxt->err_occurred) xml_ereport(xmlerrcxt, ERROR, ERRCODE_INTERNAL_ERROR, "invalid XPath expression"); @@ -4819,7 +4825,10 @@ XmlTableSetRowFilter(TableFuncScanState *state, const char *path) xstr = pg_xmlCharStrndup(path, strlen(path)); - xtCxt->xpathcomp = xmlXPathCompile(xstr); + /* We require XmlTableSetDocument to have been done already */ + Assert(xtCxt->xpathcxt != NULL); + + xtCxt->xpathcomp = xmlXPathCtxtCompile(xtCxt->xpathcxt, xstr); if (xtCxt->xpathcomp == NULL || xtCxt->xmlerrcxt->err_occurred) xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_SYNTAX_ERROR, "invalid XPath expression"); @@ -4850,7 +4859,10 @@ XmlTableSetColumnFilter(TableFuncScanState *state, const char *path, int colnum) xstr = pg_xmlCharStrndup(path, strlen(path)); - xtCxt->xpathscomp[colnum] = xmlXPathCompile(xstr); + /* We require XmlTableSetDocument to have been done already */ + Assert(xtCxt->xpathcxt != NULL); + + xtCxt->xpathscomp[colnum] = xmlXPathCtxtCompile(xtCxt->xpathcxt, xstr); if (xtCxt->xpathscomp[colnum] == NULL || xtCxt->xmlerrcxt->err_occurred) xml_ereport(xtCxt->xmlerrcxt, ERROR, ERRCODE_DATA_EXCEPTION, "invalid XPath expression"); |