1 | #include "fuzz.h" |
2 | |
3 | static void |
4 | test_bytes (const guint8 *data, |
5 | gsize size) |
6 | { |
7 | GError *error = NULL; |
8 | GBytes *unescaped_bytes = NULL; |
9 | gchar *escaped_string = NULL; |
10 | |
11 | if (size > G_MAXSSIZE) |
12 | return; |
13 | |
14 | unescaped_bytes = g_uri_unescape_bytes (escaped_string: (const gchar *) data, length: (gssize) size, NULL, error: &error); |
15 | if (unescaped_bytes == NULL) |
16 | { |
17 | g_assert_nonnull (error); |
18 | g_clear_error (err: &error); |
19 | return; |
20 | } |
21 | |
22 | escaped_string = g_uri_escape_bytes (unescaped: g_bytes_get_data (bytes: unescaped_bytes, NULL), |
23 | length: g_bytes_get_size (bytes: unescaped_bytes), |
24 | NULL); |
25 | g_bytes_unref (bytes: unescaped_bytes); |
26 | |
27 | if (escaped_string == NULL) |
28 | return; |
29 | |
30 | g_free (mem: escaped_string); |
31 | } |
32 | |
33 | static void |
34 | test_string (const guint8 *data, |
35 | gsize size) |
36 | { |
37 | gchar *unescaped_string = NULL; |
38 | gchar *escaped_string = NULL; |
39 | |
40 | unescaped_string = g_uri_unescape_segment (escaped_string: (const gchar *) data, escaped_string_end: (const gchar *) data + size, NULL); |
41 | if (unescaped_string == NULL) |
42 | return; |
43 | |
44 | escaped_string = g_uri_escape_string (unescaped: unescaped_string, NULL, TRUE); |
45 | g_free (mem: unescaped_string); |
46 | |
47 | if (escaped_string == NULL) |
48 | return; |
49 | |
50 | g_free (mem: escaped_string); |
51 | } |
52 | |
53 | int |
54 | LLVMFuzzerTestOneInput (const unsigned char *data, size_t size) |
55 | { |
56 | fuzz_set_logging_func (); |
57 | |
58 | /* Bytes form */ |
59 | test_bytes (data, size); |
60 | |
61 | /* String form (doesn’t do %-decoding) */ |
62 | test_string (data, size); |
63 | |
64 | return 0; |
65 | } |
66 | |