2020-06-21 15:42:00 +03:00
/*
* schema . c : a libFuzzer target to test the XML Schema processor .
*
* See Copyright for the status of this software .
*/
2021-02-22 23:28:21 +03:00
# include <libxml/catalog.h>
2020-06-21 15:42:00 +03:00
# include <libxml/xmlschemas.h>
# include "fuzz.h"
int
LLVMFuzzerInitialize ( int * argc ATTRIBUTE_UNUSED ,
char * * * argv ATTRIBUTE_UNUSED ) {
2023-03-08 15:59:03 +03:00
xmlFuzzMemSetup ( ) ;
2020-06-21 15:42:00 +03:00
xmlInitParser ( ) ;
2021-02-22 23:28:21 +03:00
# ifdef LIBXML_CATALOG_ENABLED
xmlInitializeCatalog ( ) ;
2024-01-04 17:18:14 +03:00
xmlCatalogSetDefaults ( XML_CATA_ALLOW_NONE ) ;
2021-02-22 23:28:21 +03:00
# endif
2020-06-21 15:42:00 +03:00
return 0 ;
}
int
LLVMFuzzerTestOneInput ( const char * data , size_t size ) {
xmlSchemaParserCtxtPtr pctxt ;
2023-03-08 15:59:03 +03:00
size_t maxAlloc ;
2020-06-21 15:42:00 +03:00
2020-12-16 17:41:52 +03:00
if ( size > 50000 )
return ( 0 ) ;
2023-12-10 20:32:21 +03:00
maxAlloc = xmlFuzzReadInt ( 4 ) % ( size + 100 ) ;
2023-03-08 15:59:03 +03:00
2020-06-21 15:42:00 +03:00
xmlFuzzDataInit ( data , size ) ;
xmlFuzzReadEntities ( ) ;
2023-03-08 15:59:03 +03:00
xmlFuzzMemSetLimit ( maxAlloc ) ;
2020-06-21 15:42:00 +03:00
pctxt = xmlSchemaNewParserCtxt ( xmlFuzzMainUrl ( ) ) ;
2024-06-11 17:58:09 +03:00
xmlSchemaSetParserStructuredErrors ( pctxt , xmlFuzzSErrorFunc , NULL ) ;
2024-06-11 16:48:32 +03:00
xmlSchemaSetResourceLoader ( pctxt , xmlFuzzResourceLoader , NULL ) ;
2020-06-21 15:42:00 +03:00
xmlSchemaFree ( xmlSchemaParse ( pctxt ) ) ;
xmlSchemaFreeParserCtxt ( pctxt ) ;
2023-03-08 15:59:03 +03:00
xmlFuzzMemSetLimit ( 0 ) ;
2020-06-21 15:42:00 +03:00
xmlFuzzDataCleanup ( ) ;
2021-02-22 23:28:21 +03:00
xmlResetLastError ( ) ;
2020-06-21 15:42:00 +03:00
return ( 0 ) ;
}