VirtualBox

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

最後變更 在這個檔案從108403是 105420,由 vboxsync 提交於 8 月 前

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

  • 屬性 svn:eol-style 設為 native
檔案大小: 1.2 KB
 
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
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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