mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-01-31 13:47:30 +03:00
- catalog.c: handling of CATALOG entries. detection of recursion,
and a few bugfixes - xpath.c: fixing bug #54951 QNAME with no prefix should not match against the default namespace Daniel
This commit is contained in:
parent
04b93290b7
commit
af86c7f463
@ -1,3 +1,10 @@
|
|||||||
|
Mon May 21 16:05:22 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
||||||
|
|
||||||
|
* catalog.c: handling of CATALOG entries. detection of recursion,
|
||||||
|
and a few bugfixes
|
||||||
|
* xpath.c: fixing bug #54951 QNAME with no prefix should not match
|
||||||
|
against the default namespace
|
||||||
|
|
||||||
Mon May 21 10:14:07 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
Mon May 21 10:14:07 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
||||||
|
|
||||||
* xpath.c: Joe Orton reported a bug found with IRIx compiler.
|
* xpath.c: Joe Orton reported a bug found with IRIx compiler.
|
||||||
|
84
catalog.c
84
catalog.c
@ -64,6 +64,12 @@ struct _xmlCatalogEntry {
|
|||||||
|
|
||||||
static xmlHashTablePtr xmlDefaultCatalog;
|
static xmlHashTablePtr xmlDefaultCatalog;
|
||||||
|
|
||||||
|
/* Catalog stack */
|
||||||
|
const char * catalTab[10]; /* stack of catals */
|
||||||
|
const char * catal; /* Current catal stream */
|
||||||
|
int catalNr = 0; /* Number of current catal streams */
|
||||||
|
int catalMax = 10; /* Max number of catal streams */
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
* alloc or dealloc *
|
* alloc or dealloc *
|
||||||
@ -81,8 +87,8 @@ xmlNewCatalogEntry(int type, xmlChar *name, xmlChar *value) {
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
ret->type = type;
|
ret->type = type;
|
||||||
ret->name = name;
|
ret->name = xmlStrdup(name);
|
||||||
ret->value = value;
|
ret->value = xmlStrdup(value);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +199,7 @@ xmlParseCatalogComment(const xmlChar *cur) {
|
|||||||
if (cur[0] == 0) {
|
if (cur[0] == 0) {
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
return(cur);
|
return(cur + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const xmlChar *
|
static const xmlChar *
|
||||||
@ -289,6 +295,7 @@ static int
|
|||||||
xmlParseCatalog(const xmlChar *value, const char *file) {
|
xmlParseCatalog(const xmlChar *value, const char *file) {
|
||||||
const xmlChar *cur = value;
|
const xmlChar *cur = value;
|
||||||
xmlChar *base = NULL;
|
xmlChar *base = NULL;
|
||||||
|
int res;
|
||||||
|
|
||||||
if ((cur == NULL) || (file == NULL))
|
if ((cur == NULL) || (file == NULL))
|
||||||
return(-1);
|
return(-1);
|
||||||
@ -348,9 +355,11 @@ xmlParseCatalog(const xmlChar *value, const char *file) {
|
|||||||
/* error */
|
/* error */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
xmlFree(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
xmlFree(name);
|
xmlFree(name);
|
||||||
|
name = NULL;
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case XML_CATA_ENTITY:
|
case XML_CATA_ENTITY:
|
||||||
@ -417,28 +426,39 @@ xmlParseCatalog(const xmlChar *value, const char *file) {
|
|||||||
} else if (type == XML_CATA_BASE) {
|
} else if (type == XML_CATA_BASE) {
|
||||||
if (base != NULL)
|
if (base != NULL)
|
||||||
xmlFree(base);
|
xmlFree(base);
|
||||||
base = sysid;
|
base = xmlStrdup(sysid);
|
||||||
} else if ((type == XML_CATA_PUBLIC) ||
|
} else if ((type == XML_CATA_PUBLIC) ||
|
||||||
(type == XML_CATA_SYSTEM)) {
|
(type == XML_CATA_SYSTEM)) {
|
||||||
xmlChar *filename;
|
xmlChar *filename;
|
||||||
|
|
||||||
filename = xmlBuildURI(sysid, base);
|
filename = xmlBuildURI(sysid, base);
|
||||||
if (filename != NULL) {
|
if (filename != NULL) {
|
||||||
|
xmlCatalogEntryPtr entry;
|
||||||
|
|
||||||
xmlHashAddEntry(xmlDefaultCatalog, name,
|
entry = xmlNewCatalogEntry(type, name, filename);
|
||||||
xmlNewCatalogEntry(type, name, filename));
|
res = xmlHashAddEntry(xmlDefaultCatalog, name, entry);
|
||||||
|
if (res < 0) {
|
||||||
|
xmlFreeCatalogEntry(entry);
|
||||||
|
}
|
||||||
|
xmlFree(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (type == XML_CATA_CATALOG) {
|
||||||
|
xmlChar *filename;
|
||||||
|
|
||||||
|
filename = xmlBuildURI(sysid, base);
|
||||||
|
if (filename != NULL) {
|
||||||
|
xmlLoadCatalog((const char *)filename);
|
||||||
|
xmlFree(filename);
|
||||||
}
|
}
|
||||||
if (sysid != NULL)
|
|
||||||
xmlFree(sysid);
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* drop anything else we won't handle it
|
|
||||||
*/
|
|
||||||
if (name != NULL)
|
|
||||||
xmlFree(name);
|
|
||||||
if (sysid != NULL)
|
|
||||||
xmlFree(sysid);
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* drop anything else we won't handle it
|
||||||
|
*/
|
||||||
|
if (name != NULL)
|
||||||
|
xmlFree(name);
|
||||||
|
if (sysid != NULL)
|
||||||
|
xmlFree(sysid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (base != NULL)
|
if (base != NULL)
|
||||||
@ -460,17 +480,20 @@ xmlParseCatalog(const xmlChar *value, const char *file) {
|
|||||||
*
|
*
|
||||||
* Load the catalog and makes its definition effective for the default
|
* Load the catalog and makes its definition effective for the default
|
||||||
* external entity loader.
|
* external entity loader.
|
||||||
|
* TODO: this function is not thread safe, catalog initialization should
|
||||||
|
* be done once at startup
|
||||||
*
|
*
|
||||||
* Returns 0 in case of success -1 in case of error
|
* Returns 0 in case of success -1 in case of error
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xmlLoadCatalog(const char *filename) {
|
xmlLoadCatalog(const char *filename) {
|
||||||
int fd, len, ret;
|
int fd, len, ret, i;
|
||||||
struct stat info;
|
struct stat info;
|
||||||
xmlChar *content;
|
xmlChar *content;
|
||||||
|
|
||||||
if (filename == NULL)
|
if (filename == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
if (xmlDefaultCatalog == NULL)
|
if (xmlDefaultCatalog == NULL)
|
||||||
xmlDefaultCatalog = xmlHashCreate(20);
|
xmlDefaultCatalog = xmlHashCreate(20);
|
||||||
if (xmlDefaultCatalog == NULL)
|
if (xmlDefaultCatalog == NULL)
|
||||||
@ -479,17 +502,41 @@ xmlLoadCatalog(const char *filename) {
|
|||||||
if (stat(filename, &info) < 0)
|
if (stat(filename, &info) < 0)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
/*
|
||||||
|
* Prevent loops
|
||||||
|
*/
|
||||||
|
for (i = 0;i < catalNr;i++) {
|
||||||
|
if (xmlStrEqual(catalTab[i], filename)) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
|
"xmlLoadCatalog: %s seems to induce a loop\n",
|
||||||
|
filename);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (catalNr >= catalMax) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
|
"xmlLoadCatalog: %s catalog list too deep\n",
|
||||||
|
filename);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
catalTab[catalNr++] = filename;
|
||||||
|
|
||||||
|
if ((fd = open(filename, O_RDONLY)) < 0) {
|
||||||
|
catalNr--;
|
||||||
return(-1);
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
content = xmlMalloc(info.st_size + 10);
|
content = xmlMalloc(info.st_size + 10);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"realloc of %d byte failed\n", info.st_size + 10);
|
"realloc of %d byte failed\n", info.st_size + 10);
|
||||||
|
catalNr--;
|
||||||
|
return(-1);
|
||||||
}
|
}
|
||||||
len = read(fd, content, info.st_size);
|
len = read(fd, content, info.st_size);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
xmlFree(content);
|
xmlFree(content);
|
||||||
|
catalNr--;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
content[len] = 0;
|
content[len] = 0;
|
||||||
@ -497,6 +544,7 @@ xmlLoadCatalog(const char *filename) {
|
|||||||
|
|
||||||
ret = xmlParseCatalog(content, filename);
|
ret = xmlParseCatalog(content, filename);
|
||||||
xmlFree(content);
|
xmlFree(content);
|
||||||
|
catalNr--;
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
xpath.c
3
xpath.c
@ -7348,8 +7348,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
|
|||||||
case XML_ELEMENT_NODE:
|
case XML_ELEMENT_NODE:
|
||||||
if (xmlStrEqual(name, cur->name)) {
|
if (xmlStrEqual(name, cur->name)) {
|
||||||
if (prefix == NULL) {
|
if (prefix == NULL) {
|
||||||
if ((cur->ns == NULL) ||
|
if (cur->ns == NULL) {
|
||||||
(cur->ns->prefix == NULL)) {
|
|
||||||
#ifdef DEBUG_STEP
|
#ifdef DEBUG_STEP
|
||||||
n++;
|
n++;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user