2020-06-05 12:49:25 +02:00
|
|
|
/*
|
|
|
|
* fuzz.h: Common functions and macros for fuzzing.
|
|
|
|
*
|
|
|
|
* See Copyright for the status of this software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __XML_FUZZERCOMMON_H__
|
|
|
|
#define __XML_FUZZERCOMMON_H__
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2020-08-24 03:16:25 +02:00
|
|
|
#include <stdio.h>
|
2020-06-05 12:49:25 +02:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2024-06-16 20:02:45 -07:00
|
|
|
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 207 || defined(__clang__)
|
2024-06-15 19:13:08 +02:00
|
|
|
#define ATTRIBUTE_UNUSED __attribute__((unused))
|
|
|
|
#else
|
|
|
|
#define ATTRIBUTE_UNUSED
|
|
|
|
#endif
|
|
|
|
|
2023-09-21 13:05:49 +02:00
|
|
|
#if defined(LIBXML_HTML_ENABLED)
|
2021-02-22 21:26:13 +01:00
|
|
|
#define HAVE_HTML_FUZZER
|
|
|
|
#endif
|
2024-05-13 12:18:08 +02:00
|
|
|
#if 1
|
|
|
|
#define HAVE_LINT_FUZZER
|
|
|
|
#endif
|
2024-04-16 13:24:12 +02:00
|
|
|
#if defined(LIBXML_READER_ENABLED)
|
|
|
|
#define HAVE_READER_FUZZER
|
|
|
|
#endif
|
2021-02-22 21:26:13 +01:00
|
|
|
#if defined(LIBXML_REGEXP_ENABLED)
|
|
|
|
#define HAVE_REGEXP_FUZZER
|
|
|
|
#endif
|
|
|
|
#if defined(LIBXML_SCHEMAS_ENABLED)
|
|
|
|
#define HAVE_SCHEMA_FUZZER
|
|
|
|
#endif
|
|
|
|
#if 1
|
|
|
|
#define HAVE_URI_FUZZER
|
|
|
|
#endif
|
2023-09-21 13:05:49 +02:00
|
|
|
#if defined(LIBXML_VALID_ENABLED)
|
2023-03-12 16:15:54 +01:00
|
|
|
#define HAVE_VALID_FUZZER
|
|
|
|
#endif
|
2023-09-21 13:05:49 +02:00
|
|
|
#if defined(LIBXML_XINCLUDE_ENABLED)
|
2022-12-26 17:49:27 +01:00
|
|
|
#define HAVE_XINCLUDE_FUZZER
|
|
|
|
#endif
|
2023-09-21 13:05:49 +02:00
|
|
|
#if 1
|
2021-02-22 21:26:13 +01:00
|
|
|
#define HAVE_XML_FUZZER
|
|
|
|
#endif
|
2023-09-21 01:29:40 +02:00
|
|
|
#if defined(LIBXML_XPTR_ENABLED)
|
2021-02-22 21:26:13 +01:00
|
|
|
#define HAVE_XPATH_FUZZER
|
|
|
|
#endif
|
|
|
|
|
2024-12-11 16:24:23 +01:00
|
|
|
#define XML_FUZZ_PROB_ONE (1u << 16)
|
|
|
|
|
|
|
|
typedef size_t
|
|
|
|
(*xmlFuzzMutator)(char *data, size_t size, size_t maxSize);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned size;
|
|
|
|
unsigned mutateProb;
|
|
|
|
} xmlFuzzChunkDesc;
|
|
|
|
|
2020-06-05 12:49:25 +02:00
|
|
|
int
|
|
|
|
LLVMFuzzerInitialize(int *argc, char ***argv);
|
|
|
|
|
|
|
|
int
|
|
|
|
LLVMFuzzerTestOneInput(const char *data, size_t size);
|
|
|
|
|
2024-12-11 16:24:23 +01:00
|
|
|
size_t
|
|
|
|
LLVMFuzzerMutate(char *data, size_t size, size_t maxSize);
|
|
|
|
|
|
|
|
size_t
|
|
|
|
LLVMFuzzerCustomMutator(char *data, size_t size, size_t maxSize,
|
|
|
|
unsigned seed);
|
|
|
|
|
2020-06-05 12:49:25 +02:00
|
|
|
void
|
2024-06-11 16:58:09 +02:00
|
|
|
xmlFuzzErrorFunc(void *ctx, const char *msg, ...);
|
|
|
|
|
|
|
|
void
|
|
|
|
xmlFuzzSErrorFunc(void *ctx, const xmlError *error);
|
2020-06-05 12:49:25 +02:00
|
|
|
|
2023-03-08 13:59:03 +01:00
|
|
|
void
|
|
|
|
xmlFuzzMemSetup(void);
|
|
|
|
|
|
|
|
void
|
2024-11-25 19:41:33 +01:00
|
|
|
xmlFuzzInjectFailure(size_t failurePos);
|
2023-03-08 13:59:03 +01:00
|
|
|
|
2023-09-22 17:03:56 +02:00
|
|
|
int
|
|
|
|
xmlFuzzMallocFailed(void);
|
|
|
|
|
2023-12-10 14:46:59 +01:00
|
|
|
void
|
2024-11-25 19:41:33 +01:00
|
|
|
xmlFuzzResetFailure(void);
|
2023-12-10 14:46:59 +01:00
|
|
|
|
|
|
|
void
|
2024-11-25 19:41:33 +01:00
|
|
|
xmlFuzzCheckFailureReport(const char *func, int oomReport, int ioReport);
|
2023-12-10 14:46:59 +01:00
|
|
|
|
2020-06-05 12:49:25 +02:00
|
|
|
void
|
|
|
|
xmlFuzzDataInit(const char *data, size_t size);
|
|
|
|
|
|
|
|
void
|
|
|
|
xmlFuzzDataCleanup(void);
|
|
|
|
|
2023-03-08 13:59:00 +01:00
|
|
|
void
|
|
|
|
xmlFuzzWriteInt(FILE *out, size_t v, int size);
|
|
|
|
|
|
|
|
size_t
|
|
|
|
xmlFuzzReadInt(int size);
|
2020-06-05 12:49:25 +02:00
|
|
|
|
2024-02-29 14:51:49 +01:00
|
|
|
size_t
|
|
|
|
xmlFuzzBytesRemaining(void);
|
|
|
|
|
2020-06-15 12:20:54 +02:00
|
|
|
const char *
|
|
|
|
xmlFuzzReadRemaining(size_t *size);
|
|
|
|
|
2020-08-06 13:20:01 +02:00
|
|
|
void
|
|
|
|
xmlFuzzWriteString(FILE *out, const char *str);
|
|
|
|
|
|
|
|
const char *
|
|
|
|
xmlFuzzReadString(size_t *size);
|
|
|
|
|
2020-06-05 12:49:25 +02:00
|
|
|
void
|
|
|
|
xmlFuzzReadEntities(void);
|
|
|
|
|
2020-06-21 14:42:00 +02:00
|
|
|
const char *
|
|
|
|
xmlFuzzMainUrl(void);
|
|
|
|
|
2020-06-05 12:49:25 +02:00
|
|
|
const char *
|
|
|
|
xmlFuzzMainEntity(size_t *size);
|
|
|
|
|
2024-12-10 15:54:12 +01:00
|
|
|
const char *
|
|
|
|
xmlFuzzSecondaryUrl(void);
|
|
|
|
|
|
|
|
const char *
|
|
|
|
xmlFuzzSecondaryEntity(size_t *size);
|
|
|
|
|
2024-06-11 15:48:32 +02:00
|
|
|
int
|
|
|
|
xmlFuzzResourceLoader(void *data, const char *URL, const char *ID,
|
2025-03-13 23:20:16 +01:00
|
|
|
xmlResourceType type, xmlParserInputFlags flags,
|
|
|
|
xmlParserInputPtr *out);
|
2024-06-11 15:48:32 +02:00
|
|
|
|
2020-08-24 03:16:25 +02:00
|
|
|
char *
|
|
|
|
xmlSlurpFile(const char *path, size_t *size);
|
|
|
|
|
2024-12-17 18:26:24 +01:00
|
|
|
int
|
|
|
|
xmlFuzzOutputWrite(void *ctxt, const char *buffer, int len);
|
|
|
|
|
|
|
|
int
|
|
|
|
xmlFuzzOutputClose(void *ctxt);
|
|
|
|
|
2024-12-11 16:24:23 +01:00
|
|
|
size_t
|
|
|
|
xmlFuzzMutateChunks(const xmlFuzzChunkDesc *chunks,
|
|
|
|
char *data, size_t size, size_t maxSize, unsigned seed,
|
|
|
|
xmlFuzzMutator mutator);
|
|
|
|
|
2020-06-05 12:49:25 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __XML_FUZZERCOMMON_H__ */
|
|
|
|
|