VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/fuzz/schema.c@ 104106

Last change on this file since 104106 was 104106, checked in by vboxsync, 11 months ago

libxml2-2.9.14: Applied and adjusted our libxml2 changes to 2.9.14. bugref:10640

  • Property svn:eol-style set to native
File size: 1.1 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#endif
19 xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
20 xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
21
22 return 0;
23}
24
25int
26LLVMFuzzerTestOneInput(const char *data, size_t size) {
27 xmlSchemaParserCtxtPtr pctxt;
28 size_t maxAlloc;
29
30 if (size > 50000)
31 return(0);
32
33 maxAlloc = xmlFuzzReadInt(4) % (size + 1);
34
35 xmlFuzzDataInit(data, size);
36 xmlFuzzReadEntities();
37
38 xmlFuzzMemSetLimit(maxAlloc);
39 pctxt = xmlSchemaNewParserCtxt(xmlFuzzMainUrl());
40 xmlSchemaSetParserErrors(pctxt, xmlFuzzErrorFunc, xmlFuzzErrorFunc, NULL);
41 xmlSchemaFree(xmlSchemaParse(pctxt));
42 xmlSchemaFreeParserCtxt(pctxt);
43
44 xmlFuzzMemSetLimit(0);
45 xmlFuzzDataCleanup();
46 xmlResetLastError();
47
48 return(0);
49}
50
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