summaryrefslogtreecommitdiff
path: root/fuzzing/fuzz_uri_parse.c
blob: 4faed62a1badad70c811dfc61dd788f48bc48e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "fuzz.h"

static void
test_with_flags (const gchar *data,
                 GUriFlags    flags)
{
  GUri *uri = NULL;
  gchar *uri_string = NULL;

  uri = g_uri_parse (data, flags, NULL);

  if (uri == NULL)
    return;

  uri_string = g_uri_to_string (uri);
  g_uri_unref (uri);

  if (uri_string == NULL)
    return;

  g_free (uri_string);
}

int
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
{
  unsigned char *nul_terminated_data = NULL;

  fuzz_set_logging_func ();

  /* ignore @size (g_uri_parse() doesn’t support it); ensure @data is nul-terminated */
  nul_terminated_data = (unsigned char *) g_strndup ((const gchar *) data, size);
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_NONE);
  test_with_flags ((const gchar *) nul_terminated_data, G_URI_FLAGS_PARSE_STRICT);
  g_free (nul_terminated_data);

  return 0;
}