1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

fuzz: Move back to xmlSetExternalEntityLoader

xmlParserInputBufferCreateFilenameDefault can't report malloc failures.
This commit is contained in:
Nick Wellnhofer 2024-05-19 19:31:54 +02:00
parent 4fefba4cf6
commit caa8bb3848
11 changed files with 36 additions and 13 deletions

View File

@ -964,7 +964,7 @@ LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlParserInputBufferCreateFilenameDefault(xmlFuzzEntityLoader);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
return 0;
}

View File

@ -391,8 +391,10 @@ xmlFuzzMainEntity(size_t *size) {
*
* The entity loader for fuzz data.
*/
xmlParserInputBufferPtr
xmlFuzzEntityLoader(const char *URL, xmlCharEncoding enc) {
xmlParserInputPtr
xmlFuzzEntityLoader(const char *URL, const char *ID ATTRIBUTE_UNUSED,
xmlParserCtxtPtr ctxt) {
xmlParserInputPtr input;
xmlFuzzEntityInfo *entity;
if (URL == NULL)
@ -401,7 +403,26 @@ xmlFuzzEntityLoader(const char *URL, xmlCharEncoding enc) {
if (entity == NULL)
return(NULL);
return(xmlParserInputBufferCreateMem(entity->data, entity->size, enc));
input = xmlNewInputStream(ctxt);
if (input == NULL)
return(NULL);
input->filename = (char *) xmlCharStrdup(URL);
if (input->filename == NULL) {
xmlCtxtErrMemory(ctxt);
xmlFreeInputStream(input);
return(NULL);
}
input->buf = xmlParserInputBufferCreateMem(entity->data, entity->size,
XML_CHAR_ENCODING_NONE);
if (input->buf == NULL) {
xmlCtxtErrMemory(ctxt);
xmlFreeInputStream(input);
return(NULL);
}
input->base = input->cur = xmlBufContent(input->buf->buffer);
input->end = input->base + xmlBufUse(input->buf->buffer);
return input;
}
char *

View File

@ -104,8 +104,8 @@ xmlFuzzMainUrl(void);
const char *
xmlFuzzMainEntity(size_t *size);
xmlParserInputBufferPtr
xmlFuzzEntityLoader(const char *URL, xmlCharEncoding enc);
xmlParserInputPtr
xmlFuzzEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt);
char *
xmlSlurpFile(const char *path, size_t *size);

View File

@ -198,7 +198,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
pushArg(NULL);
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlParserInputBufferCreateFilenameDefault(xmlFuzzEntityLoader);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
#ifdef LIBXML_CATALOG_ENABLED
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
#endif

View File

@ -102,7 +102,7 @@ LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlParserInputBufferCreateFilenameDefault(xmlFuzzEntityLoader);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
return 0;
}

View File

@ -18,7 +18,7 @@ LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlParserInputBufferCreateFilenameDefault(xmlFuzzEntityLoader);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
return 0;
}

View File

@ -162,7 +162,7 @@ testEntityLoader(void) {
xmlDocPtr doc;
int ret = 0;
xmlParserInputBufferCreateFilenameDefault(xmlFuzzEntityLoader);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
xmlFuzzDataInit(data, sizeof(data) - 1);
xmlFuzzReadEntities();

View File

@ -20,7 +20,7 @@ LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlParserInputBufferCreateFilenameDefault(xmlFuzzEntityLoader);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
return 0;
}

View File

@ -21,7 +21,7 @@ LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlParserInputBufferCreateFilenameDefault(xmlFuzzEntityLoader);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
return 0;
}

View File

@ -21,7 +21,7 @@ LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlParserInputBufferCreateFilenameDefault(xmlFuzzEntityLoader);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
return 0;
}

View File

@ -3506,7 +3506,9 @@ xmllintMain(int argc, const char **argv) {
else if ((!strcmp(argv[i], "-nonet")) ||
(!strcmp(argv[i], "--nonet"))) {
options |= XML_PARSE_NONET;
#ifndef XMLLINT_FUZZ
xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
#endif
} else if ((!strcmp(argv[i], "-nocompact")) ||
(!strcmp(argv[i], "--nocompact"))) {
options &= ~XML_PARSE_COMPACT;