Skip to content

Commit

Permalink
parser: Check return value of inputPush
Browse files Browse the repository at this point in the history
inputPush typically doesn't fail because we pre-allocate the input
table. The return value should be checked nevertheless.
  • Loading branch information
nwellnhof committed Jul 8, 2024
1 parent ea31ac5 commit 2e63656
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 17 deletions.
24 changes: 20 additions & 4 deletions HTMLparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 5 additions & 1 deletion catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
47 changes: 38 additions & 9 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion xinclude.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion xmlreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 5 additions & 1 deletion xmlschemas.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2e63656

Please sign in to comment.