From f5257d92bf88dbcafdb73d98fa21eb77b2650d6e Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 11 Dec 2024 16:24:43 +0100 Subject: [PATCH] fuzz: Fix failure injection in schema fuzzer --- fuzz/api.c | 4 +++- fuzz/schema.c | 9 ++++++++- fuzz/testFuzzer.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/fuzz/api.c b/fuzz/api.c index 0bbe8ce7..c2831f93 100644 --- a/fuzz/api.c +++ b/fuzz/api.c @@ -35,7 +35,9 @@ #include #include -#define XML_DEPRECATED +#ifndef XML_DEPRECATED + #define XML_DEPRECATED +#endif #include #include diff --git a/fuzz/schema.c b/fuzz/schema.c index 388fdc55..edc30c09 100644 --- a/fuzz/schema.c +++ b/fuzz/schema.c @@ -4,8 +4,13 @@ * See Copyright for the status of this software. */ +#ifndef XML_DEPRECATED + #define XML_DEPRECATED +#endif + #include #include +#include #include "fuzz.h" int @@ -30,9 +35,10 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) { if (size > 200000) return(0); + xmlFuzzDataInit(data, size); + failurePos = xmlFuzzReadInt(4) % (size + 100); - xmlFuzzDataInit(data, size); xmlFuzzReadEntities(); xmlFuzzInjectFailure(failurePos); @@ -66,6 +72,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) { xmlFuzzInjectFailure(0); xmlFuzzDataCleanup(); xmlResetLastError(); + xmlSchemaCleanupTypes(); return(0); } diff --git a/fuzz/testFuzzer.c b/fuzz/testFuzzer.c index 8ffc1f09..1045ab57 100644 --- a/fuzz/testFuzzer.c +++ b/fuzz/testFuzzer.c @@ -5,6 +5,10 @@ * See Copyright for the status of this software. */ +#ifndef XML_DEPRECATED + #define XML_DEPRECATED +#endif + #include #include #include