1 | /*
|
---|
2 | * uri.c: a libFuzzer target to test the URI module.
|
---|
3 | *
|
---|
4 | * See Copyright for the status of this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <libxml/uri.h>
|
---|
8 | #include "fuzz.h"
|
---|
9 |
|
---|
10 | int
|
---|
11 | LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
|
---|
12 | char ***argv ATTRIBUTE_UNUSED) {
|
---|
13 | xmlFuzzMemSetup();
|
---|
14 | xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
|
---|
15 |
|
---|
16 | return 0;
|
---|
17 | }
|
---|
18 |
|
---|
19 | int
|
---|
20 | LLVMFuzzerTestOneInput(const char *data, size_t size) {
|
---|
21 | xmlURIPtr uri;
|
---|
22 | size_t maxAlloc;
|
---|
23 | const char *str1, *str2;
|
---|
24 | char *copy;
|
---|
25 | xmlChar *strRes;
|
---|
26 | int intRes;
|
---|
27 |
|
---|
28 | if (size > 10000)
|
---|
29 | return(0);
|
---|
30 |
|
---|
31 | xmlFuzzDataInit(data, size);
|
---|
32 | maxAlloc = xmlFuzzReadInt(4) % (size * 8 + 100);
|
---|
33 | str1 = xmlFuzzReadString(NULL);
|
---|
34 | str2 = xmlFuzzReadString(NULL);
|
---|
35 |
|
---|
36 | xmlFuzzMemSetLimit(maxAlloc);
|
---|
37 |
|
---|
38 | xmlFuzzResetMallocFailed();
|
---|
39 | intRes = xmlParseURISafe(str1, &uri);
|
---|
40 | xmlFuzzCheckMallocFailure("xmlParseURISafe", intRes == -1);
|
---|
41 |
|
---|
42 | if (uri != NULL) {
|
---|
43 | xmlFuzzResetMallocFailed();
|
---|
44 | strRes = xmlSaveUri(uri);
|
---|
45 | xmlFuzzCheckMallocFailure("xmlSaveURI", strRes == NULL);
|
---|
46 | xmlFree(strRes);
|
---|
47 | xmlFreeURI(uri);
|
---|
48 | }
|
---|
49 |
|
---|
50 | xmlFreeURI(xmlParseURI(str1));
|
---|
51 |
|
---|
52 | uri = xmlParseURIRaw(str1, 1);
|
---|
53 | xmlFree(xmlSaveUri(uri));
|
---|
54 | xmlFreeURI(uri);
|
---|
55 |
|
---|
56 | xmlFuzzResetMallocFailed();
|
---|
57 | strRes = BAD_CAST xmlURIUnescapeString(str1, -1, NULL);
|
---|
58 | xmlFuzzCheckMallocFailure("xmlURIUnescapeString",
|
---|
59 | str1 != NULL && strRes == NULL);
|
---|
60 | xmlFree(strRes);
|
---|
61 |
|
---|
62 | xmlFree(xmlURIEscape(BAD_CAST str1));
|
---|
63 |
|
---|
64 | xmlFuzzResetMallocFailed();
|
---|
65 | strRes = xmlCanonicPath(BAD_CAST str1);
|
---|
66 | xmlFuzzCheckMallocFailure("xmlCanonicPath",
|
---|
67 | str1 != NULL && strRes == NULL);
|
---|
68 | xmlFree(strRes);
|
---|
69 |
|
---|
70 | xmlFuzzResetMallocFailed();
|
---|
71 | strRes = xmlPathToURI(BAD_CAST str1);
|
---|
72 | xmlFuzzCheckMallocFailure("xmlPathToURI", str1 != NULL && strRes == NULL);
|
---|
73 | xmlFree(strRes);
|
---|
74 |
|
---|
75 | xmlFuzzResetMallocFailed();
|
---|
76 | intRes = xmlBuildURISafe(BAD_CAST str2, BAD_CAST str1, &strRes);
|
---|
77 | xmlFuzzCheckMallocFailure("xmlBuildURISafe", intRes == -1);
|
---|
78 | xmlFree(strRes);
|
---|
79 |
|
---|
80 | xmlFree(xmlBuildURI(BAD_CAST str2, BAD_CAST str1));
|
---|
81 |
|
---|
82 | xmlFuzzResetMallocFailed();
|
---|
83 | intRes = xmlBuildRelativeURISafe(BAD_CAST str2, BAD_CAST str1, &strRes);
|
---|
84 | xmlFuzzCheckMallocFailure("xmlBuildRelativeURISafe", intRes == -1);
|
---|
85 | xmlFree(strRes);
|
---|
86 |
|
---|
87 | xmlFree(xmlBuildRelativeURI(BAD_CAST str2, BAD_CAST str1));
|
---|
88 |
|
---|
89 | xmlFuzzResetMallocFailed();
|
---|
90 | strRes = xmlURIEscapeStr(BAD_CAST str1, BAD_CAST str2);
|
---|
91 | xmlFuzzCheckMallocFailure("xmlURIEscapeStr",
|
---|
92 | str1 != NULL && strRes == NULL);
|
---|
93 | xmlFree(strRes);
|
---|
94 |
|
---|
95 | copy = (char *) xmlCharStrdup(str1);
|
---|
96 | xmlNormalizeURIPath(copy);
|
---|
97 | xmlFree(copy);
|
---|
98 |
|
---|
99 | xmlFuzzMemSetLimit(0);
|
---|
100 | xmlFuzzDataCleanup();
|
---|
101 |
|
---|
102 | return 0;
|
---|
103 | }
|
---|
104 |
|
---|