2020-06-05 12:49:25 +02:00
|
|
|
/*
|
|
|
|
* regexp.c: a libFuzzer target to test the regexp module.
|
|
|
|
*
|
|
|
|
* See Copyright for the status of this software.
|
|
|
|
*/
|
|
|
|
|
2023-09-22 17:03:56 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-06-05 12:49:25 +02:00
|
|
|
#include <libxml/xmlregexp.h>
|
|
|
|
#include "fuzz.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
|
|
|
|
char ***argv ATTRIBUTE_UNUSED) {
|
2023-03-08 13:59:03 +01:00
|
|
|
xmlFuzzMemSetup();
|
2020-06-05 12:49:25 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
LLVMFuzzerTestOneInput(const char *data, size_t size) {
|
|
|
|
xmlRegexpPtr regexp;
|
2024-11-25 19:41:33 +01:00
|
|
|
size_t failurePos;
|
2023-03-08 13:59:03 +01:00
|
|
|
const char *str1;
|
2020-06-05 12:49:25 +02:00
|
|
|
|
2020-12-16 15:41:52 +01:00
|
|
|
if (size > 200)
|
|
|
|
return(0);
|
|
|
|
|
2023-03-08 13:59:03 +01:00
|
|
|
xmlFuzzDataInit(data, size);
|
2024-11-25 19:41:33 +01:00
|
|
|
failurePos = xmlFuzzReadInt(4) % (size * 8 + 100);
|
2023-03-08 13:59:03 +01:00
|
|
|
str1 = xmlFuzzReadString(NULL);
|
2020-06-05 12:49:25 +02:00
|
|
|
|
2024-11-25 19:41:33 +01:00
|
|
|
xmlFuzzInjectFailure(failurePos);
|
2023-09-22 15:25:40 +02:00
|
|
|
regexp = xmlRegexpCompile(BAD_CAST str1);
|
2023-09-22 17:03:56 +02:00
|
|
|
if (xmlFuzzMallocFailed() && regexp != NULL) {
|
|
|
|
fprintf(stderr, "malloc failure not reported\n");
|
|
|
|
abort();
|
|
|
|
}
|
2023-09-22 15:25:40 +02:00
|
|
|
/* xmlRegexpExec has pathological performance in too many cases. */
|
2020-06-05 12:49:25 +02:00
|
|
|
#if 0
|
2023-09-22 15:25:40 +02:00
|
|
|
xmlRegexpExec(regexp, BAD_CAST str2);
|
2020-06-05 12:49:25 +02:00
|
|
|
#endif
|
2023-09-22 15:25:40 +02:00
|
|
|
xmlRegFreeRegexp(regexp);
|
2020-06-05 12:49:25 +02:00
|
|
|
|
2024-11-25 19:41:33 +01:00
|
|
|
xmlFuzzInjectFailure(0);
|
2023-03-08 13:59:03 +01:00
|
|
|
xmlFuzzDataCleanup();
|
2021-02-22 21:28:21 +01:00
|
|
|
xmlResetLastError();
|
2020-06-05 12:49:25 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-12-11 16:24:23 +01:00
|
|
|
size_t
|
|
|
|
LLVMFuzzerCustomMutator(char *data, size_t size, size_t maxSize,
|
|
|
|
unsigned seed) {
|
|
|
|
static const xmlFuzzChunkDesc chunks[] = {
|
|
|
|
{ 4, XML_FUZZ_PROB_ONE / 10 }, /* failurePos */
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
return xmlFuzzMutateChunks(chunks, data, size, maxSize, seed,
|
|
|
|
LLVMFuzzerMutate);
|
|
|
|
}
|
|
|
|
|