Debian Codegraph @

fuzz/fuzz.h

raw
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 __GNUC__ * 100 + __GNUC_MINOR__ >= 207 || defined(__clang__)
19 #define ATTRIBUTE_UNUSED __attribute__((unused))
20 #else
21 #define ATTRIBUTE_UNUSED
22 #endif
23
24 #if defined(LIBXML_HTML_ENABLED)
25 #define HAVE_HTML_FUZZER
26 #endif
27 #if 1
28 #define HAVE_LINT_FUZZER
29 #endif
30 #if defined(LIBXML_READER_ENABLED)
31 #define HAVE_READER_FUZZER
32 #endif
33 #if defined(LIBXML_REGEXP_ENABLED)
34 #define HAVE_REGEXP_FUZZER
35 #endif
36 #if defined(LIBXML_SCHEMAS_ENABLED)
37 #define HAVE_SCHEMA_FUZZER
38 #endif
39 #if 1
40 #define HAVE_URI_FUZZER
41 #endif
42 #if defined(LIBXML_VALID_ENABLED)
43 #define HAVE_VALID_FUZZER
44 #endif
45 #if defined(LIBXML_XINCLUDE_ENABLED)
46 #define HAVE_XINCLUDE_FUZZER
47 #endif
48 #if 1
49 #define HAVE_XML_FUZZER
50 #endif
51 #if defined(LIBXML_XPTR_ENABLED)
52 #define HAVE_XPATH_FUZZER
53 #endif
54
55 #define XML_FUZZ_PROB_ONE (1u << 16)
56
57 typedef size_t
58 (*xmlFuzzMutator)(char *data, size_t size, size_t maxSize);
59
60 typedef struct {
61 unsigned size;
62 unsigned mutateProb;
63 } xmlFuzzChunkDesc;
64
65 int
66 LLVMFuzzerInitialize(int *argc, char ***argv);
67
68 int
69 LLVMFuzzerTestOneInput(const char *data, size_t size);
70
71 size_t
72 LLVMFuzzerMutate(char *data, size_t size, size_t maxSize);
73
74 size_t
75 LLVMFuzzerCustomMutator(char *data, size_t size, size_t maxSize,
76 unsigned seed);
77
78 void
79 xmlFuzzErrorFunc(void *ctx, const char *msg, ...);
80
81 void
82 xmlFuzzSErrorFunc(void *ctx, const xmlError *error);
83
84 void
85 xmlFuzzMemSetup(void);
86
87 void
88 xmlFuzzInjectFailure(size_t failurePos);
89
90 int
91 xmlFuzzMallocFailed(void);
92
93 void
94 xmlFuzzResetFailure(void);
95
96 void
97 xmlFuzzCheckFailureReport(const char *func, int oomReport, int ioReport);
98
99 void
100 xmlFuzzDataInit(const char *data, size_t size);
101
102 void
103 xmlFuzzDataCleanup(void);
104
105 void
106 xmlFuzzWriteInt(FILE *out, size_t v, int size);
107
108 size_t
109 xmlFuzzReadInt(int size);
110
111 size_t
112 xmlFuzzBytesRemaining(void);
113
114 const char *
115 xmlFuzzReadRemaining(size_t *size);
116
117 void
118 xmlFuzzWriteString(FILE *out, const char *str);
119
120 const char *
121 xmlFuzzReadString(size_t *size);
122
123 void
124 xmlFuzzReadEntities(void);
125
126 const char *
127 xmlFuzzMainUrl(void);
128
129 const char *
130 xmlFuzzMainEntity(size_t *size);
131
132 const char *
133 xmlFuzzSecondaryUrl(void);
134
135 const char *
136 xmlFuzzSecondaryEntity(size_t *size);
137
138 xmlParserErrors
139 xmlFuzzResourceLoader(void *data, const char *URL, const char *ID,
140 xmlResourceType type, xmlParserInputFlags flags,
141 xmlParserInputPtr *out);
142
143 char *
144 xmlSlurpFile(const char *path, size_t *size);
145
146 int
147 xmlFuzzOutputWrite(void *ctxt, const char *buffer, int len);
148
149 int
150 xmlFuzzOutputClose(void *ctxt);
151
152 size_t
153 xmlFuzzMutateChunks(const xmlFuzzChunkDesc *chunks,
154 char *data, size_t size, size_t maxSize, unsigned seed,
155 xmlFuzzMutator mutator);
156
157 #ifdef __cplusplus
158 }
159 #endif
160
161 #endif /* __XML_FUZZERCOMMON_H__ */
162