Coverage Report

Created: 2025-07-11 06:47

/src/tinysparql/fuzzing/fuzz_query.c
Line
Count
Source
1
/*
2
 * Copyright 2024 Red Hat Inc.
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
 * Author: Carlos Garnacho <carlosg@gnome.org>
20
 */
21
22
#include "fuzz.h"
23
24
5.39k
#define MAX_SIZE 800 * 1024
25
26
int
27
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
28
5.39k
{
29
5.39k
  static TrackerSparqlConnection *conn = NULL;
30
5.39k
  TrackerSparqlStatement *stmt;
31
5.39k
  unsigned char *nul_terminated_data = NULL;
32
33
5.39k
  sqlite3_config (SQLITE_CONFIG_LOOKASIDE, 0, 0);
34
35
5.39k
  fuzz_set_logging_func ();
36
37
5.39k
  if (size > MAX_SIZE)
38
1
    return 0;
39
40
5.39k
  if (!conn) {
41
1
    GFile *ontology;
42
43
    /* Point to empty ontology */
44
1
    ontology = g_file_new_for_uri ("resource:///");
45
1
    conn = tracker_sparql_connection_new (TRACKER_SPARQL_CONNECTION_FLAGS_NONE,
46
1
                                          NULL,
47
1
                                          ontology,
48
1
                                          NULL, NULL);
49
1
    g_clear_object (&ontology);
50
1
  }
51
52
5.39k
  nul_terminated_data = (unsigned char *) g_strndup ((const gchar *) data, size);
53
5.39k
  stmt = tracker_sparql_connection_query_statement (conn,
54
5.39k
                                                    (const gchar *) nul_terminated_data,
55
5.39k
                                                    NULL, NULL);
56
57
5.39k
  g_clear_object (&stmt);
58
59
5.39k
  stmt = tracker_sparql_connection_update_statement (conn,
60
5.39k
                                                     (const gchar *) nul_terminated_data,
61
5.39k
                                                     NULL, NULL);
62
5.39k
  g_clear_object (&stmt);
63
5.39k
  g_free (nul_terminated_data);
64
65
5.39k
  return 0;
66
5.39k
}