Coverage Report

Created: 2026-07-25 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/glib/fuzzing/fuzz_uri_escape.c
Line
Count
Source
1
/*
2
 * Copyright 2020 Endless OS Foundation, LLC
3
 * Copyright 2020 Red Hat, Inc.
4
 *
5
 * SPDX-License-Identifier: LGPL-2.1-or-later
6
 *
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.
11
 *
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.
16
 *
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/>.
19
 */
20
21
#include "fuzz.h"
22
23
static void
24
test_bytes (const guint8 *data,
25
            gsize         size)
26
569
{
27
569
  GError *error = NULL;
28
569
  GBytes *unescaped_bytes = NULL;
29
569
  gchar *escaped_string = NULL;
30
31
569
  if (size > G_MAXSSIZE)
32
0
    return;
33
34
569
  unescaped_bytes = g_uri_unescape_bytes ((const gchar *) data, (gssize) size, NULL, &error);
35
569
  if (unescaped_bytes == NULL)
36
6
    {
37
6
      g_assert_nonnull (error);
38
6
      g_clear_error (&error);
39
6
      return;
40
6
    }
41
42
563
  escaped_string = g_uri_escape_bytes (g_bytes_get_data (unescaped_bytes, NULL),
43
563
                                       g_bytes_get_size (unescaped_bytes),
44
563
                                       NULL);
45
563
  g_bytes_unref (unescaped_bytes);
46
47
563
  if (escaped_string == NULL)
48
0
    return;
49
50
563
  g_free (escaped_string);
51
563
}
52
53
static void
54
test_string (const guint8 *data,
55
             gsize         size)
56
569
{
57
569
  gchar *unescaped_string = NULL;
58
569
  gchar *escaped_string = NULL;
59
60
569
  unescaped_string = g_uri_unescape_segment ((const gchar *) data, (const gchar *) data + size, NULL);
61
569
  if (unescaped_string == NULL)
62
91
    return;
63
64
478
  escaped_string = g_uri_escape_string (unescaped_string, NULL, TRUE);
65
478
  g_free (unescaped_string);
66
67
478
  if (escaped_string == NULL)
68
0
    return;
69
70
478
  g_free (escaped_string);
71
478
}
72
73
int
74
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
75
19.9k
{
76
19.9k
  fuzz_set_logging_func ();
77
78
  /* Bytes form */
79
19.9k
  test_bytes (data, size);
80
81
  /* String form (doesn’t do %-decoding) */
82
19.9k
  test_string (data, size);
83
84
19.9k
  return 0;
85
19.9k
}