2 * Copyright 2020 Endless OS Foundation, LLC
3 * Copyright 2020 Red Hat, Inc.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
24 test_bytes (const guint8 *data,
28 GBytes *unescaped_bytes = NULL;
29 gchar *escaped_string = NULL;
31 if (size > G_MAXSSIZE)
34 unescaped_bytes = g_uri_unescape_bytes ((const gchar *) data, (gssize) size, NULL, &error);
35 if (unescaped_bytes == NULL)
37 g_assert_nonnull (error);
38 g_clear_error (&error);
42 escaped_string = g_uri_escape_bytes (g_bytes_get_data (unescaped_bytes, NULL),
43 g_bytes_get_size (unescaped_bytes),
45 g_bytes_unref (unescaped_bytes);
47 if (escaped_string == NULL)
50 g_free (escaped_string);
54 test_string (const guint8 *data,
57 gchar *unescaped_string = NULL;
58 gchar *escaped_string = NULL;
60 unescaped_string = g_uri_unescape_segment ((const gchar *) data, (const gchar *) data + size, NULL);
61 if (unescaped_string == NULL)
64 escaped_string = g_uri_escape_string (unescaped_string, NULL, TRUE);
65 g_free (unescaped_string);
67 if (escaped_string == NULL)
70 g_free (escaped_string);
74 LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
76 fuzz_set_logging_func ();
79 test_bytes (data, size);
81 /* String form (doesn’t do %-decoding) */
82 test_string (data, size);