mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-10-26 12:25:09 +03:00
parser: Allow to disable catalogs with parser options
Implement XML_PARSE_NO_SYS_CATALOG and XML_PARSE_NO_CATALOG_PI. Fixes #735.
This commit is contained in:
parent
6794c1b91d
commit
606f410891
@ -3409,6 +3409,9 @@ xmlCatalogConvert(void) {
|
||||
/**
|
||||
* xmlCatalogGetDefaults:
|
||||
*
|
||||
* DEPRECATED: Use XML_PARSE_NO_SYS_CATALOG and
|
||||
* XML_PARSE_NO_CATALOG_PI.
|
||||
*
|
||||
* Used to get the user preference w.r.t. to what catalogs should
|
||||
* be accepted
|
||||
*
|
||||
@ -3423,6 +3426,9 @@ xmlCatalogGetDefaults(void) {
|
||||
* xmlCatalogSetDefaults:
|
||||
* @allow: what catalogs should be accepted
|
||||
*
|
||||
* DEPRECATED: Use XML_PARSE_NO_SYS_CATALOG and
|
||||
* XML_PARSE_NO_CATALOG_PI.
|
||||
*
|
||||
* Used to set the user preference w.r.t. to what catalogs should
|
||||
* be accepted
|
||||
*/
|
||||
|
@ -1391,7 +1391,9 @@ typedef enum {
|
||||
/* since 2.13.0 */
|
||||
XML_PARSE_NO_XXE = 1<<23,/* disable loading of external content */
|
||||
/* since 2.14.0 */
|
||||
XML_PARSE_NO_UNZIP = 1<<24 /* disable compressed content */
|
||||
XML_PARSE_NO_UNZIP = 1<<24,/* disable compressed content */
|
||||
XML_PARSE_NO_SYS_CATALOG = 1<<25,/* disable global system catalog */
|
||||
XML_PARSE_NO_CATALOG_PI = 1<<26 /* ignore catalog PIs */
|
||||
} xmlParserOption;
|
||||
|
||||
XMLPUBFUN void
|
||||
|
19
parser.c
19
parser.c
@ -5536,13 +5536,14 @@ xmlParsePI(xmlParserCtxtPtr ctxt) {
|
||||
if ((ctxt->inSubset == 0) &&
|
||||
(xmlStrEqual(target, XML_CATALOG_PI))) {
|
||||
xmlCatalogAllow allow = xmlCatalogGetDefaults();
|
||||
if ((allow == XML_CATA_ALLOW_DOCUMENT) ||
|
||||
(allow == XML_CATA_ALLOW_ALL))
|
||||
|
||||
if (((ctxt->options & XML_PARSE_NO_CATALOG_PI) == 0) &&
|
||||
((allow == XML_CATA_ALLOW_DOCUMENT) ||
|
||||
(allow == XML_CATA_ALLOW_ALL)))
|
||||
xmlParseCatalogPI(ctxt, buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* SAX: PI detected.
|
||||
*/
|
||||
@ -13619,6 +13620,18 @@ xmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask)
|
||||
*
|
||||
* Available since 2.14.0.
|
||||
*
|
||||
* XML_PARSE_NO_SYS_CATALOG
|
||||
*
|
||||
* Disables the global system XML catalog.
|
||||
*
|
||||
* Available since 2.14.0.
|
||||
*
|
||||
* XML_PARSE_NO_CATALOG_PI
|
||||
*
|
||||
* Ignore XML catalog processing instructions.
|
||||
*
|
||||
* Available since 2.14.0.
|
||||
*
|
||||
* Returns 0 in case of success, the set of unknown or unimplemented options
|
||||
* in case of error.
|
||||
*/
|
||||
|
@ -2199,6 +2199,8 @@ xmlResolveResourceFromCatalog(const char *URL, const char *ID,
|
||||
xmlParserCtxtPtr ctxt) {
|
||||
xmlChar *resource = NULL;
|
||||
xmlCatalogAllow pref;
|
||||
int allowLocal = 0;
|
||||
int allowGlobal = 0;
|
||||
|
||||
/*
|
||||
* If the resource doesn't exists as a file,
|
||||
@ -2206,13 +2208,22 @@ xmlResolveResourceFromCatalog(const char *URL, const char *ID,
|
||||
*/
|
||||
pref = xmlCatalogGetDefaults();
|
||||
|
||||
if ((ctxt != NULL) && (ctxt->catalogs != NULL) &&
|
||||
((pref == XML_CATA_ALLOW_ALL) ||
|
||||
(pref == XML_CATA_ALLOW_DOCUMENT)))
|
||||
allowLocal = 1;
|
||||
|
||||
if (((ctxt == NULL) ||
|
||||
((ctxt->options & XML_PARSE_NO_SYS_CATALOG) == 0)) &&
|
||||
((pref == XML_CATA_ALLOW_ALL) ||
|
||||
(pref == XML_CATA_ALLOW_GLOBAL)))
|
||||
allowGlobal = 1;
|
||||
|
||||
if ((pref != XML_CATA_ALLOW_NONE) && (!xmlNoNetExists(URL))) {
|
||||
/*
|
||||
* Do a local lookup
|
||||
*/
|
||||
if ((ctxt != NULL) && (ctxt->catalogs != NULL) &&
|
||||
((pref == XML_CATA_ALLOW_ALL) ||
|
||||
(pref == XML_CATA_ALLOW_DOCUMENT))) {
|
||||
if (allowLocal) {
|
||||
resource = xmlCatalogLocalResolve(ctxt->catalogs,
|
||||
(const xmlChar *)ID,
|
||||
(const xmlChar *)URL);
|
||||
@ -2220,9 +2231,7 @@ xmlResolveResourceFromCatalog(const char *URL, const char *ID,
|
||||
/*
|
||||
* Try a global lookup
|
||||
*/
|
||||
if ((resource == NULL) &&
|
||||
((pref == XML_CATA_ALLOW_ALL) ||
|
||||
(pref == XML_CATA_ALLOW_GLOBAL))) {
|
||||
if ((resource == NULL) && (allowGlobal)) {
|
||||
resource = xmlCatalogResolve((const xmlChar *)ID,
|
||||
(const xmlChar *)URL);
|
||||
}
|
||||
@ -2235,14 +2244,10 @@ xmlResolveResourceFromCatalog(const char *URL, const char *ID,
|
||||
if ((resource != NULL) && (!xmlNoNetExists((const char *)resource))) {
|
||||
xmlChar *tmp = NULL;
|
||||
|
||||
if ((ctxt != NULL) && (ctxt->catalogs != NULL) &&
|
||||
((pref == XML_CATA_ALLOW_ALL) ||
|
||||
(pref == XML_CATA_ALLOW_DOCUMENT))) {
|
||||
if (allowLocal) {
|
||||
tmp = xmlCatalogLocalResolveURI(ctxt->catalogs, resource);
|
||||
}
|
||||
if ((tmp == NULL) &&
|
||||
((pref == XML_CATA_ALLOW_ALL) ||
|
||||
(pref == XML_CATA_ALLOW_GLOBAL))) {
|
||||
if ((tmp == NULL) && (allowGlobal)) {
|
||||
tmp = xmlCatalogResolveURI(resource);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user