/* * testFuzzer.c: Test program for the custom entity loader used to fuzz * with multiple inputs. * * See Copyright for the status of this software. */ #include #include #include #include #include "fuzz.h" int main() { static const char data[] = "doc.xml\\\n" "\n" "&ent;\\\n" "doc.dtd\\\n" "\n" "\\\n" "ent.txt\\\n" "Hello, world!\\\n"; static xmlChar expected[] = "\n" "\n" "Hello, world!\n"; const char *docBuffer; size_t docSize; xmlDocPtr doc; xmlChar *out; int ret = 0; xmlSetExternalEntityLoader(xmlFuzzEntityLoader); xmlFuzzDataInit(data, sizeof(data) - 1); xmlFuzzReadEntities(); docBuffer = xmlFuzzMainEntity(&docSize); doc = xmlReadMemory(docBuffer, docSize, NULL, NULL, XML_PARSE_NOENT | XML_PARSE_DTDLOAD); xmlDocDumpMemory(doc, &out, NULL); if (xmlStrcmp(out, expected) != 0) { fprintf(stderr, "Expected:\n%sGot:\n%s", expected, out); ret = 1; } xmlFree(out); xmlFreeDoc(doc); xmlFuzzDataCleanup(); return(ret); }