1 /*
2  * fuzz.h: Common functions and macros for fuzzing.
3  *
4  * See Copyright for the status of this software.
5  */
6 
7 #ifndef __XML_FUZZERCOMMON_H__
8 #define __XML_FUZZERCOMMON_H__
9 
10 #include <stddef.h>
11 #include <stdio.h>
12 #include <libxml/parser.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
19   #define HAVE_HTML_FUZZER
20 #endif
21 #if defined(LIBXML_REGEXP_ENABLED)
22   #define HAVE_REGEXP_FUZZER
23 #endif
24 #if defined(LIBXML_SCHEMAS_ENABLED)
25   #define HAVE_SCHEMA_FUZZER
26 #endif
27 #if 1
28   #define HAVE_URI_FUZZER
29 #endif
30 #if defined(LIBXML_OUTPUT_ENABLED) && \
31     defined(LIBXML_READER_ENABLED) && \
32     defined(LIBXML_XINCLUDE_ENABLED)
33   #define HAVE_XML_FUZZER
34 #endif
35 #if defined(LIBXML_XPATH_ENABLED)
36   #define HAVE_XPATH_FUZZER
37 #endif
38 
39 int
40 LLVMFuzzerInitialize(int *argc, char ***argv);
41 
42 int
43 LLVMFuzzerTestOneInput(const char *data, size_t size);
44 
45 void
46 xmlFuzzErrorFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg ATTRIBUTE_UNUSED,
47                  ...);
48 
49 void
50 xmlFuzzDataInit(const char *data, size_t size);
51 
52 void
53 xmlFuzzDataCleanup(void);
54 
55 int
56 xmlFuzzReadInt(void);
57 
58 const char *
59 xmlFuzzReadRemaining(size_t *size);
60 
61 void
62 xmlFuzzWriteString(FILE *out, const char *str);
63 
64 const char *
65 xmlFuzzReadString(size_t *size);
66 
67 void
68 xmlFuzzReadEntities(void);
69 
70 const char *
71 xmlFuzzMainUrl(void);
72 
73 const char *
74 xmlFuzzMainEntity(size_t *size);
75 
76 xmlParserInputPtr
77 xmlFuzzEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt);
78 
79 size_t
80 xmlFuzzExtractStrings(const char *data, size_t size, char **strings,
81                       size_t numStrings);
82 
83 char *
84 xmlSlurpFile(const char *path, size_t *size);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* __XML_FUZZERCOMMON_H__ */
91 
92