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) 19 #define HAVE_HTML_FUZZER 20 #endif 21 #if 1 22 #define HAVE_LINT_FUZZER 23 #endif 24 #if defined(LIBXML_READER_ENABLED) 25 #define HAVE_READER_FUZZER 26 #endif 27 #if defined(LIBXML_REGEXP_ENABLED) 28 #define HAVE_REGEXP_FUZZER 29 #endif 30 #if defined(LIBXML_SCHEMAS_ENABLED) 31 #define HAVE_SCHEMA_FUZZER 32 #endif 33 #if 1 34 #define HAVE_URI_FUZZER 35 #endif 36 #if defined(LIBXML_VALID_ENABLED) 37 #define HAVE_VALID_FUZZER 38 #endif 39 #if defined(LIBXML_XINCLUDE_ENABLED) 40 #define HAVE_XINCLUDE_FUZZER 41 #endif 42 #if 1 43 #define HAVE_XML_FUZZER 44 #endif 45 #if defined(LIBXML_XPTR_ENABLED) 46 #define HAVE_XPATH_FUZZER 47 #endif 48 49 int 50 LLVMFuzzerInitialize(int *argc, char ***argv); 51 52 int 53 LLVMFuzzerTestOneInput(const char *data, size_t size); 54 55 void 56 xmlFuzzErrorFunc(void *ctx, const char *msg, ...); 57 58 void 59 xmlFuzzSErrorFunc(void *ctx, const xmlError *error); 60 61 void 62 xmlFuzzMemSetup(void); 63 64 void 65 xmlFuzzMemSetLimit(size_t limit); 66 67 int 68 xmlFuzzMallocFailed(void); 69 70 void 71 xmlFuzzResetMallocFailed(void); 72 73 void 74 xmlFuzzCheckMallocFailure(const char *func, int expect); 75 76 void 77 xmlFuzzDataInit(const char *data, size_t size); 78 79 void 80 xmlFuzzDataCleanup(void); 81 82 void 83 xmlFuzzWriteInt(FILE *out, size_t v, int size); 84 85 size_t 86 xmlFuzzReadInt(int size); 87 88 size_t 89 xmlFuzzBytesRemaining(void); 90 91 const char * 92 xmlFuzzReadRemaining(size_t *size); 93 94 void 95 xmlFuzzWriteString(FILE *out, const char *str); 96 97 const char * 98 xmlFuzzReadString(size_t *size); 99 100 void 101 xmlFuzzReadEntities(void); 102 103 const char * 104 xmlFuzzMainUrl(void); 105 106 const char * 107 xmlFuzzMainEntity(size_t *size); 108 109 int 110 xmlFuzzResourceLoader(void *data, const char *URL, const char *ID, 111 xmlResourceType type, int flags, xmlParserInputPtr *out); 112 113 xmlParserInputPtr 114 xmlFuzzEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt); 115 116 char * 117 xmlSlurpFile(const char *path, size_t *size); 118 119 #ifdef __cplusplus 120 } 121 #endif 122 123 #endif /* __XML_FUZZERCOMMON_H__ */ 124 125