workspace->ctxt->node = xmlDocGetRootElement(workspace->doctree);
/* compile the path */
- comppath = xmlXPathCompile(xpath);
+ comppath = xmlXPathCtxtCompile(workspace->ctxt, xpath);
if (comppath == NULL)
xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
"XPath Syntax Error");
ctxt->node = xmlDocGetRootElement(doctree);
/* compile the path */
- comppath = xmlXPathCompile(xpaths[j]);
+ comppath = xmlXPathCtxtCompile(ctxt, xpaths[j]);
if (comppath == NULL)
xml_ereport(xmlerrcxt, ERROR,
ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
}
}
- 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");
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");
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");