parser: Check return value of inputPush

inputPush typically doesn't fail because we pre-allocate the input
table. The return value should be checked nevertheless.
This commit is contained in:
Nick Wellnhofer 2024-07-07 19:21:46 +02:00
parent ea31ac5bba
commit 2e63656ec6
6 changed files with 76 additions and 17 deletions

View File

@ -5033,7 +5033,11 @@ htmlCreateMemoryParserCtxtInternal(const char *url,
return(NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
return(ctxt);
}
@ -5086,7 +5090,11 @@ htmlCreateDocParserCtxt(const xmlChar *str, const char *url,
return(NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
return(ctxt);
}
@ -5815,7 +5823,11 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
return(NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
if (encoding != NULL)
xmlSwitchEncodingName(ctxt, encoding);
@ -5921,7 +5933,11 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
xmlFreeParserCtxt(ctxt);
return(NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
return(ctxt);
}

View File

@ -903,7 +903,11 @@ xmlParseCatalogFile(const char *filename) {
inputStream->buf = buf;
xmlBufResetInput(buf->buffer, inputStream);
inputPush(ctxt, inputStream);
if (inputPush(ctxt, inputStream) < 0) {
xmlFreeInputStream(inputStream);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
ctxt->valid = 0;
ctxt->validate = 0;

View File

@ -7951,7 +7951,10 @@ xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
xmlBufResetInput(input->buf->buffer, input);
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
goto error;
}
xmlDetectEncoding(ctxt);
@ -11698,7 +11701,11 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
xmlFreeParserCtxt(ctxt);
return(NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
return(ctxt);
}
@ -11752,7 +11759,11 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
xmlFreeParserCtxt(ctxt);
return (NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
return(ctxt);
}
@ -12686,8 +12697,10 @@ xmlCreateEntityParserCtxt(const xmlChar *URL, const xmlChar *ID,
if (input == NULL)
goto error;
if (inputPush(ctxt, input) < 0)
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
goto error;
}
xmlFree(uri);
return(ctxt);
@ -12735,7 +12748,11 @@ xmlCreateURLParserCtxt(const char *filename, int options)
xmlFreeParserCtxt(ctxt);
return(NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
return(ctxt);
}
@ -12915,7 +12932,8 @@ xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer,
input = xmlNewInputString(ctxt, filename, (const char *) buffer, NULL, 0);
if (input == NULL)
return;
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0)
xmlFreeInputStream(input);
}
/**
@ -13002,7 +13020,11 @@ xmlCreateMemoryParserCtxt(const char *buffer, int size) {
xmlFreeParserCtxt(ctxt);
return(NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
return(ctxt);
}
@ -13188,7 +13210,11 @@ xmlCreateDocParserCtxt(const xmlChar *str) {
xmlFreeParserCtxt(ctxt);
return(NULL);
}
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
return(ctxt);
}
@ -13407,7 +13433,10 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk,
if (input == NULL)
return(1);
inputPush(ctxt, input);
if (inputPush(ctxt, input) < 0) {
xmlFreeInputStream(input);
return(1);
}
if (encoding != NULL)
xmlSwitchEncodingName(ctxt, encoding);

View File

@ -351,7 +351,10 @@ xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) {
if (inputStream == NULL)
goto error;
inputPush(pctxt, inputStream);
if (inputPush(pctxt, inputStream) < 0) {
xmlFreeInputStream(inputStream);
goto error;
}
xmlParseDocument(pctxt);

View File

@ -4988,7 +4988,10 @@ xmlTextReaderSetup(xmlTextReaderPtr reader,
inputStream->buf = buf;
xmlBufResetInput(buf->buffer, inputStream);
inputPush(reader->ctxt, inputStream);
if (inputPush(reader->ctxt, inputStream) < 0) {
xmlFreeInputStream(inputStream);
return(-1);
}
reader->cur = 0;
}
}

View File

@ -28806,7 +28806,11 @@ xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt,
ret = -1;
goto done;
}
inputPush(pctxt, inputStream);
if (inputPush(pctxt, inputStream) < 0) {
xmlFreeInputStream(inputStream);
ret = -1;
goto done;
}
ctxt->enc = enc;