Coverage Report

Created: 2025-11-16 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/glib/fuzzing/fuzz_uri_parse.c
Line
Count
Source
1
/*
2
 * Copyright 2020 Endless OS Foundation, LLC
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
#include "fuzz.h"
21
22
static void
23
test_with_flags (const gchar *data,
24
                 GUriFlags    flags)
25
33.5k
{
26
33.5k
  GUri *uri = NULL;
27
33.5k
  gchar *uri_string = NULL;
28
29
33.5k
  uri = g_uri_parse (data, flags, NULL);
30
31
33.5k
  if (uri == NULL)
32
27.2k
    return;
33
34
6.33k
  uri_string = g_uri_to_string (uri);
35
6.33k
  g_uri_unref (uri);
36
37
6.33k
  if (uri_string == NULL)
38
22
    return;
39
40
6.31k
  g_free (uri_string);
41
6.31k
}
42
43
int
44
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
45
17.4k
{
46
17.4k
  unsigned char *nul_terminated_data = NULL;
47
48
17.4k
  fuzz_set_logging_func ();
49
50
  /* ignore @size (g_uri_parse() doesn’t support it); ensure @data is nul-terminated */
51
17.4k
  nul_terminated_data = (unsigned char *) g_strndup ((const gchar *) data, size);
52
17.4k
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_NONE);
53
17.4k
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_PARSE_RELAXED);
54
17.4k
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_NON_DNS);
55
17.4k
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_HAS_AUTH_PARAMS);
56
17.4k
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_HAS_PASSWORD);
57
17.4k
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_ENCODED_QUERY);
58
17.4k
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_ENCODED_PATH);
59
17.4k
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_SCHEME_NORMALIZE);
60
17.4k
  g_free (nul_terminated_data);
61
62
17.4k
  return 0;
63
17.4k
}