1 #include "fuzz.h"
2
3 static void
test_bytes(const guint8 * data,gsize size)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 ((const gchar *) data, (gssize) size, NULL, &error);
15 if (unescaped_bytes == NULL)
16 {
17 g_assert_nonnull (error);
18 g_clear_error (&error);
19 return;
20 }
21
22 escaped_string = g_uri_escape_bytes (g_bytes_get_data (unescaped_bytes, NULL),
23 g_bytes_get_size (unescaped_bytes),
24 NULL);
25 g_bytes_unref (unescaped_bytes);
26
27 if (escaped_string == NULL)
28 return;
29
30 g_free (escaped_string);
31 }
32
33 static void
test_string(const guint8 * data,gsize size)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 ((const gchar *) data, (const gchar *) data + size, NULL);
41 if (unescaped_string == NULL)
42 return;
43
44 escaped_string = g_uri_escape_string (unescaped_string, NULL, TRUE);
45 g_free (unescaped_string);
46
47 if (escaped_string == NULL)
48 return;
49
50 g_free (escaped_string);
51 }
52
53 int
LLVMFuzzerTestOneInput(const unsigned char * data,size_t size)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