1 /* 2 * schema.c: a libFuzzer target to test the XML Schema processor. 3 * 4 * See Copyright for the status of this software. 5 */ 6 7 #include <libxml/catalog.h> 8 #include <libxml/xmlschemas.h> 9 #include "fuzz.h" 10 11 int LLVMFuzzerInitialize(int * argc ATTRIBUTE_UNUSED,char *** argv ATTRIBUTE_UNUSED)12LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED, 13 char ***argv ATTRIBUTE_UNUSED) { 14 xmlInitParser(); 15 #ifdef LIBXML_CATALOG_ENABLED 16 xmlInitializeCatalog(); 17 #endif 18 xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc); 19 xmlSetExternalEntityLoader(xmlFuzzEntityLoader); 20 21 return 0; 22 } 23 24 int LLVMFuzzerTestOneInput(const char * data,size_t size)25LLVMFuzzerTestOneInput(const char *data, size_t size) { 26 xmlSchemaParserCtxtPtr pctxt; 27 28 if (size > 50000) 29 return(0); 30 31 xmlFuzzDataInit(data, size); 32 xmlFuzzReadEntities(); 33 34 pctxt = xmlSchemaNewParserCtxt(xmlFuzzMainUrl()); 35 xmlSchemaSetParserErrors(pctxt, xmlFuzzErrorFunc, xmlFuzzErrorFunc, NULL); 36 xmlSchemaFree(xmlSchemaParse(pctxt)); 37 xmlSchemaFreeParserCtxt(pctxt); 38 39 xmlFuzzDataCleanup(); 40 xmlResetLastError(); 41 42 return(0); 43 } 44 45