1 | #include "fuzz.h" |
2 | |
3 | static void |
4 | test_with_flags (const gchar *data, |
5 | GUriFlags flags) |
6 | { |
7 | GUri *uri = NULL; |
8 | gchar *uri_string = NULL; |
9 | |
10 | uri = g_uri_parse (uri_string: data, flags, NULL); |
11 | |
12 | if (uri == NULL) |
13 | return; |
14 | |
15 | uri_string = g_uri_to_string (uri); |
16 | g_uri_unref (uri); |
17 | |
18 | if (uri_string == NULL) |
19 | return; |
20 | |
21 | g_free (mem: uri_string); |
22 | } |
23 | |
24 | int |
25 | LLVMFuzzerTestOneInput (const unsigned char *data, size_t size) |
26 | { |
27 | unsigned char *nul_terminated_data = NULL; |
28 | |
29 | fuzz_set_logging_func (); |
30 | |
31 | /* ignore @size (g_uri_parse() doesn’t support it); ensure @data is nul-terminated */ |
32 | nul_terminated_data = (unsigned char *) g_strndup (str: (const gchar *) data, n: size); |
33 | test_with_flags (data: (const gchar *) nul_terminated_data, flags: G_URI_FLAGS_NONE); |
34 | test_with_flags (data: (const gchar *) nul_terminated_data, flags: G_URI_FLAGS_PARSE_RELAXED); |
35 | test_with_flags (data: (const gchar *) nul_terminated_data, flags: G_URI_FLAGS_NON_DNS); |
36 | test_with_flags (data: (const gchar *) nul_terminated_data, flags: G_URI_FLAGS_HAS_AUTH_PARAMS); |
37 | test_with_flags (data: (const gchar *) nul_terminated_data, flags: G_URI_FLAGS_HAS_PASSWORD); |
38 | test_with_flags (data: (const gchar *) nul_terminated_data, flags: G_URI_FLAGS_ENCODED_QUERY); |
39 | test_with_flags (data: (const gchar *) nul_terminated_data, flags: G_URI_FLAGS_ENCODED_PATH); |
40 | test_with_flags (data: (const gchar *) nul_terminated_data, flags: G_URI_FLAGS_SCHEME_NORMALIZE); |
41 | g_free (mem: nul_terminated_data); |
42 | |
43 | return 0; |
44 | } |
45 | |