VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/fuzz/schema.c@ 106180

Last change on this file since 106180 was 105420, checked in by vboxsync, 5 months ago

libxml2-2.12.6: Applied and adjusted our libxml2 changes to 2.12.6. bugref:10730

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
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
11int
12LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
13 char ***argv ATTRIBUTE_UNUSED) {
14 xmlFuzzMemSetup();
15 xmlInitParser();
16#ifdef LIBXML_CATALOG_ENABLED
17 xmlInitializeCatalog();
18 xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
19#endif
20 xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
21 xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
22
23 return 0;
24}
25
26int
27LLVMFuzzerTestOneInput(const char *data, size_t size) {
28 xmlSchemaParserCtxtPtr pctxt;
29 size_t maxAlloc;
30
31 if (size > 50000)
32 return(0);
33
34 maxAlloc = xmlFuzzReadInt(4) % (size + 100);
35
36 xmlFuzzDataInit(data, size);
37 xmlFuzzReadEntities();
38
39 xmlFuzzMemSetLimit(maxAlloc);
40 pctxt = xmlSchemaNewParserCtxt(xmlFuzzMainUrl());
41 xmlSchemaSetParserErrors(pctxt, xmlFuzzErrorFunc, xmlFuzzErrorFunc, NULL);
42 xmlSchemaFree(xmlSchemaParse(pctxt));
43 xmlSchemaFreeParserCtxt(pctxt);
44
45 xmlFuzzMemSetLimit(0);
46 xmlFuzzDataCleanup();
47 xmlResetLastError();
48
49 return(0);
50}
51
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette