xref: /aosp_15_r20/external/libxml2/fuzz/fuzz.h (revision 7c5688314b92172186c154356a6374bf7684c3ca)
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 int
56 LLVMFuzzerInitialize(int *argc, char ***argv);
57 
58 int
59 LLVMFuzzerTestOneInput(const char *data, size_t size);
60 
61 void
62 xmlFuzzErrorFunc(void *ctx, const char *msg, ...);
63 
64 void
65 xmlFuzzSErrorFunc(void *ctx, const xmlError *error);
66 
67 void
68 xmlFuzzMemSetup(void);
69 
70 void
71 xmlFuzzMemSetLimit(size_t limit);
72 
73 int
74 xmlFuzzMallocFailed(void);
75 
76 void
77 xmlFuzzResetMallocFailed(void);
78 
79 void
80 xmlFuzzCheckMallocFailure(const char *func, int expect);
81 
82 void
83 xmlFuzzDataInit(const char *data, size_t size);
84 
85 void
86 xmlFuzzDataCleanup(void);
87 
88 void
89 xmlFuzzWriteInt(FILE *out, size_t v, int size);
90 
91 size_t
92 xmlFuzzReadInt(int size);
93 
94 size_t
95 xmlFuzzBytesRemaining(void);
96 
97 const char *
98 xmlFuzzReadRemaining(size_t *size);
99 
100 void
101 xmlFuzzWriteString(FILE *out, const char *str);
102 
103 const char *
104 xmlFuzzReadString(size_t *size);
105 
106 void
107 xmlFuzzReadEntities(void);
108 
109 const char *
110 xmlFuzzMainUrl(void);
111 
112 const char *
113 xmlFuzzMainEntity(size_t *size);
114 
115 int
116 xmlFuzzResourceLoader(void *data, const char *URL, const char *ID,
117                       xmlResourceType type, int flags, xmlParserInputPtr *out);
118 
119 xmlParserInputPtr
120 xmlFuzzEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt);
121 
122 char *
123 xmlSlurpFile(const char *path, size_t *size);
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif /* __XML_FUZZERCOMMON_H__ */
130 
131