mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
parser: Fix argument checks in xmlCtxtParse*
- Raise invalid argument error. - Free input stream if ctxt is NULL.
This commit is contained in:
30
HTMLparser.c
30
HTMLparser.c
@ -5887,8 +5887,11 @@ htmlCtxtParseDocument(htmlParserCtxtPtr ctxt, xmlParserInputPtr input)
|
||||
{
|
||||
htmlDocPtr ret;
|
||||
|
||||
if ((ctxt == NULL) || (input == NULL))
|
||||
if ((ctxt == NULL) || (input == NULL)) {
|
||||
xmlFatalErr(ctxt, XML_ERR_ARGUMENT, NULL);
|
||||
xmlFreeInputStream(input);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* assert(ctxt->inputNr == 0); */
|
||||
while (ctxt->inputNr > 0)
|
||||
@ -5937,7 +5940,7 @@ htmlReadDoc(const xmlChar *str, const char *url, const char *encoding,
|
||||
{
|
||||
htmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
htmlDocPtr doc;
|
||||
htmlDocPtr doc = NULL;
|
||||
|
||||
ctxt = htmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
@ -5948,6 +5951,7 @@ htmlReadDoc(const xmlChar *str, const char *url, const char *encoding,
|
||||
input = xmlCtxtNewInputFromString(ctxt, url, (const char *) str, encoding,
|
||||
XML_INPUT_BUF_STATIC);
|
||||
|
||||
if (input != NULL)
|
||||
doc = htmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
htmlFreeParserCtxt(ctxt);
|
||||
@ -5972,7 +5976,7 @@ htmlReadFile(const char *filename, const char *encoding, int options)
|
||||
{
|
||||
htmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
htmlDocPtr doc;
|
||||
htmlDocPtr doc = NULL;
|
||||
|
||||
ctxt = htmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
@ -5982,6 +5986,7 @@ htmlReadFile(const char *filename, const char *encoding, int options)
|
||||
|
||||
input = xmlCtxtNewInputFromUrl(ctxt, filename, NULL, encoding, 0);
|
||||
|
||||
if (input != NULL)
|
||||
doc = htmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
htmlFreeParserCtxt(ctxt);
|
||||
@ -6009,7 +6014,7 @@ htmlReadMemory(const char *buffer, int size, const char *url,
|
||||
{
|
||||
htmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
htmlDocPtr doc;
|
||||
htmlDocPtr doc = NULL;
|
||||
|
||||
if (size < 0)
|
||||
return(NULL);
|
||||
@ -6023,6 +6028,7 @@ htmlReadMemory(const char *buffer, int size, const char *url,
|
||||
input = xmlCtxtNewInputFromMemory(ctxt, url, buffer, size, encoding,
|
||||
XML_INPUT_BUF_STATIC);
|
||||
|
||||
if (input != NULL)
|
||||
doc = htmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
htmlFreeParserCtxt(ctxt);
|
||||
@ -6051,7 +6057,7 @@ htmlReadFd(int fd, const char *url, const char *encoding, int options)
|
||||
{
|
||||
htmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
htmlDocPtr doc;
|
||||
htmlDocPtr doc = NULL;
|
||||
|
||||
ctxt = htmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
@ -6061,6 +6067,7 @@ htmlReadFd(int fd, const char *url, const char *encoding, int options)
|
||||
|
||||
input = xmlCtxtNewInputFromFd(ctxt, url, fd, encoding, 0);
|
||||
|
||||
if (input != NULL)
|
||||
doc = htmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
htmlFreeParserCtxt(ctxt);
|
||||
@ -6089,7 +6096,7 @@ htmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
|
||||
{
|
||||
htmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
htmlDocPtr doc;
|
||||
htmlDocPtr doc = NULL;
|
||||
|
||||
ctxt = htmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
@ -6100,6 +6107,7 @@ htmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
|
||||
input = xmlCtxtNewInputFromIO(ctxt, url, ioread, ioclose, ioctx,
|
||||
encoding, 0);
|
||||
|
||||
if (input != NULL)
|
||||
doc = htmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
htmlFreeParserCtxt(ctxt);
|
||||
@ -6134,6 +6142,8 @@ htmlCtxtReadDoc(htmlParserCtxtPtr ctxt, const xmlChar *str,
|
||||
|
||||
input = xmlCtxtNewInputFromString(ctxt, URL, (const char *) str,
|
||||
encoding, 0);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(htmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
@ -6165,6 +6175,8 @@ htmlCtxtReadFile(htmlParserCtxtPtr ctxt, const char *filename,
|
||||
htmlCtxtUseOptions(ctxt, options);
|
||||
|
||||
input = xmlCtxtNewInputFromUrl(ctxt, filename, NULL, encoding, 0);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(htmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
@ -6199,6 +6211,8 @@ htmlCtxtReadMemory(htmlParserCtxtPtr ctxt, const char *buffer, int size,
|
||||
|
||||
input = xmlCtxtNewInputFromMemory(ctxt, URL, buffer, size, encoding,
|
||||
XML_INPUT_BUF_STATIC);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(htmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
@ -6233,6 +6247,8 @@ htmlCtxtReadFd(htmlParserCtxtPtr ctxt, int fd,
|
||||
htmlCtxtUseOptions(ctxt, options);
|
||||
|
||||
input = xmlCtxtNewInputFromFd(ctxt, URL, fd, encoding, 0);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(htmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
@ -6269,6 +6285,8 @@ htmlCtxtReadIO(htmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
|
||||
|
||||
input = xmlCtxtNewInputFromIO(ctxt, URL, ioread, ioclose, ioctx,
|
||||
encoding, 0);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(htmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
|
42
parser.c
42
parser.c
@ -11780,6 +11780,12 @@ xmlCtxtParseDtd(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
|
||||
const xmlChar *publicId, const xmlChar *systemId) {
|
||||
xmlDtdPtr ret = NULL;
|
||||
|
||||
if ((ctxt == NULL) || (input == NULL)) {
|
||||
xmlFatalErr(ctxt, XML_ERR_ARGUMENT, NULL);
|
||||
xmlFreeInputStream(input);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (xmlCtxtPushInput(ctxt, input) < 0) {
|
||||
xmlFreeInputStream(input);
|
||||
return(NULL);
|
||||
@ -12808,7 +12814,7 @@ xmlCreateFileParserCtxt(const char *filename)
|
||||
xmlDocPtr
|
||||
xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename,
|
||||
int recovery, void *data) {
|
||||
xmlDocPtr ret;
|
||||
xmlDocPtr ret = NULL;
|
||||
xmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
|
||||
@ -12829,6 +12835,7 @@ xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename,
|
||||
else
|
||||
input = xmlCtxtNewInputFromUrl(ctxt, filename, NULL, NULL, 0);
|
||||
|
||||
if (input != NULL)
|
||||
ret = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
@ -13063,7 +13070,7 @@ xmlCreateMemoryParserCtxt(const char *buffer, int size) {
|
||||
xmlDocPtr
|
||||
xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const char *buffer,
|
||||
int size, int recovery, void *data) {
|
||||
xmlDocPtr ret;
|
||||
xmlDocPtr ret = NULL;
|
||||
xmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
|
||||
@ -13085,6 +13092,7 @@ xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const char *buffer,
|
||||
input = xmlCtxtNewInputFromMemory(ctxt, NULL, buffer, size, NULL,
|
||||
XML_INPUT_BUF_STATIC);
|
||||
|
||||
if (input != NULL)
|
||||
ret = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
@ -13824,8 +13832,11 @@ xmlCtxtParseDocument(xmlParserCtxtPtr ctxt, xmlParserInputPtr input)
|
||||
{
|
||||
xmlDocPtr ret = NULL;
|
||||
|
||||
if ((ctxt == NULL) || (input == NULL))
|
||||
if ((ctxt == NULL) || (input == NULL)) {
|
||||
xmlFatalErr(ctxt, XML_ERR_ARGUMENT, NULL);
|
||||
xmlFreeInputStream(input);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* assert(ctxt->inputNr == 0); */
|
||||
while (ctxt->inputNr > 0)
|
||||
@ -13877,7 +13888,7 @@ xmlReadDoc(const xmlChar *cur, const char *URL, const char *encoding,
|
||||
{
|
||||
xmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
xmlDocPtr doc;
|
||||
xmlDocPtr doc = NULL;
|
||||
|
||||
ctxt = xmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
@ -13888,6 +13899,7 @@ xmlReadDoc(const xmlChar *cur, const char *URL, const char *encoding,
|
||||
input = xmlCtxtNewInputFromString(ctxt, URL, (const char *) cur, encoding,
|
||||
XML_INPUT_BUF_STATIC);
|
||||
|
||||
if (input != NULL)
|
||||
doc = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
@ -13912,7 +13924,7 @@ xmlReadFile(const char *filename, const char *encoding, int options)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
xmlDocPtr doc;
|
||||
xmlDocPtr doc = NULL;
|
||||
|
||||
ctxt = xmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
@ -13931,6 +13943,7 @@ xmlReadFile(const char *filename, const char *encoding, int options)
|
||||
else
|
||||
input = xmlCtxtNewInputFromUrl(ctxt, filename, NULL, encoding, 0);
|
||||
|
||||
if (input != NULL)
|
||||
doc = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
@ -13958,7 +13971,7 @@ xmlReadMemory(const char *buffer, int size, const char *url,
|
||||
{
|
||||
xmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
xmlDocPtr doc;
|
||||
xmlDocPtr doc = NULL;
|
||||
|
||||
if (size < 0)
|
||||
return(NULL);
|
||||
@ -13972,6 +13985,7 @@ xmlReadMemory(const char *buffer, int size, const char *url,
|
||||
input = xmlCtxtNewInputFromMemory(ctxt, url, buffer, size, encoding,
|
||||
XML_INPUT_BUF_STATIC);
|
||||
|
||||
if (input != NULL)
|
||||
doc = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
@ -13999,7 +14013,7 @@ xmlReadFd(int fd, const char *URL, const char *encoding, int options)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
xmlDocPtr doc;
|
||||
xmlDocPtr doc = NULL;
|
||||
|
||||
ctxt = xmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
@ -14009,6 +14023,7 @@ xmlReadFd(int fd, const char *URL, const char *encoding, int options)
|
||||
|
||||
input = xmlCtxtNewInputFromFd(ctxt, URL, fd, encoding, 0);
|
||||
|
||||
if (input != NULL)
|
||||
doc = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
@ -14036,7 +14051,7 @@ xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
|
||||
{
|
||||
xmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
xmlDocPtr doc;
|
||||
xmlDocPtr doc = NULL;
|
||||
|
||||
ctxt = xmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
@ -14047,6 +14062,7 @@ xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
|
||||
input = xmlCtxtNewInputFromIO(ctxt, URL, ioread, ioclose, ioctx,
|
||||
encoding, 0);
|
||||
|
||||
if (input != NULL)
|
||||
doc = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
@ -14084,6 +14100,8 @@ xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar *str,
|
||||
|
||||
input = xmlCtxtNewInputFromString(ctxt, URL, (const char *) str, encoding,
|
||||
XML_INPUT_BUF_STATIC);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(xmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
@ -14113,6 +14131,8 @@ xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *filename,
|
||||
xmlCtxtUseOptions(ctxt, options);
|
||||
|
||||
input = xmlCtxtNewInputFromUrl(ctxt, filename, NULL, encoding, 0);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(xmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
@ -14150,6 +14170,8 @@ xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *buffer, int size,
|
||||
|
||||
input = xmlCtxtNewInputFromMemory(ctxt, URL, buffer, size, encoding,
|
||||
XML_INPUT_BUF_STATIC);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(xmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
@ -14187,6 +14209,8 @@ xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd,
|
||||
xmlCtxtUseOptions(ctxt, options);
|
||||
|
||||
input = xmlCtxtNewInputFromFd(ctxt, URL, fd, encoding, 0);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(xmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
@ -14227,6 +14251,8 @@ xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
|
||||
|
||||
input = xmlCtxtNewInputFromIO(ctxt, URL, ioread, ioclose, ioctx,
|
||||
encoding, 0);
|
||||
if (input == NULL)
|
||||
return(NULL);
|
||||
|
||||
return(xmlCtxtParseDocument(ctxt, input));
|
||||
}
|
||||
|
Reference in New Issue
Block a user