• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
LLVMFuzzerTestOneInput(const char * data,size_t size)11 LLVMFuzzerTestOneInput(const char *data, size_t size) {
12     xmlURIPtr uri;
13     char *str[2] = { NULL, NULL };
14     size_t numStrings;
15 
16     if (size > 10000)
17         return(0);
18 
19     numStrings = xmlFuzzExtractStrings(data, size, str, 2);
20 
21     uri = xmlParseURI(str[0]);
22     xmlFree(xmlSaveUri(uri));
23     xmlFreeURI(uri);
24 
25     uri = xmlParseURIRaw(str[0], 1);
26     xmlFree(xmlSaveUri(uri));
27     xmlFreeURI(uri);
28 
29     xmlFree(xmlURIUnescapeString(str[0], -1, NULL));
30     xmlFree(xmlURIEscape(BAD_CAST str[0]));
31     xmlFree(xmlCanonicPath(BAD_CAST str[0]));
32     xmlFree(xmlPathToURI(BAD_CAST str[0]));
33 
34     if (numStrings >= 2) {
35         xmlFree(xmlBuildURI(BAD_CAST str[1], BAD_CAST str[0]));
36         xmlFree(xmlBuildRelativeURI(BAD_CAST str[1], BAD_CAST str[0]));
37         xmlFree(xmlURIEscapeStr(BAD_CAST str[0], BAD_CAST str[1]));
38     }
39 
40     /* Modifies string, so must come last. */
41     xmlNormalizeURIPath(str[0]);
42 
43     xmlFree(str[0]);
44     xmlFree(str[1]);
45 
46     return 0;
47 }
48 
49