/src/libxml2/fuzz/regexp.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * regexp.c: a libFuzzer target to test the regexp module. |
3 | | * |
4 | | * See Copyright for the status of this software. |
5 | | */ |
6 | | |
7 | | #include <stdio.h> |
8 | | #include <stdlib.h> |
9 | | #include <libxml/xmlregexp.h> |
10 | | #include "fuzz.h" |
11 | | |
12 | | int |
13 | | LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED, |
14 | 2 | char ***argv ATTRIBUTE_UNUSED) { |
15 | 2 | xmlFuzzMemSetup(); |
16 | | |
17 | 2 | return 0; |
18 | 2 | } |
19 | | |
20 | | int |
21 | 6.55k | LLVMFuzzerTestOneInput(const char *data, size_t size) { |
22 | 6.55k | xmlRegexpPtr regexp; |
23 | 6.55k | size_t failurePos; |
24 | 6.55k | const char *str1; |
25 | | |
26 | 6.55k | if (size > 200) |
27 | 2 | return(0); |
28 | | |
29 | 6.55k | xmlFuzzDataInit(data, size); |
30 | 6.55k | failurePos = xmlFuzzReadInt(4) % (size * 8 + 100); |
31 | 6.55k | str1 = xmlFuzzReadString(NULL); |
32 | | |
33 | 6.55k | xmlFuzzInjectFailure(failurePos); |
34 | 6.55k | regexp = xmlRegexpCompile(BAD_CAST str1); |
35 | 6.55k | if (xmlFuzzMallocFailed() && regexp != NULL) { |
36 | 0 | fprintf(stderr, "malloc failure not reported\n"); |
37 | 0 | abort(); |
38 | 0 | } |
39 | | /* xmlRegexpExec has pathological performance in too many cases. */ |
40 | | #if 0 |
41 | | xmlRegexpExec(regexp, BAD_CAST str2); |
42 | | #endif |
43 | 6.55k | xmlRegFreeRegexp(regexp); |
44 | | |
45 | 6.55k | xmlFuzzInjectFailure(0); |
46 | 6.55k | xmlFuzzDataCleanup(); |
47 | 6.55k | xmlResetLastError(); |
48 | | |
49 | 6.55k | return 0; |
50 | 6.55k | } |
51 | | |
52 | | size_t |
53 | | LLVMFuzzerCustomMutator(char *data, size_t size, size_t maxSize, |
54 | 0 | unsigned seed) { |
55 | 0 | static const xmlFuzzChunkDesc chunks[] = { |
56 | 0 | { 4, XML_FUZZ_PROB_ONE / 10 }, /* failurePos */ |
57 | 0 | { 0, 0 } |
58 | 0 | }; |
59 | |
|
60 | 0 | return xmlFuzzMutateChunks(chunks, data, size, maxSize, seed, |
61 | 0 | LLVMFuzzerMutate); |
62 | 0 | } |
63 | | |