File: fuzz_query.c

package info (click to toggle)
tinysparql 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,528 kB
  • sloc: ansic: 119,209; python: 6,139; javascript: 725; sh: 121; perl: 106; xml: 67; makefile: 31; sql: 1
file content (66 lines) | stat: -rw-r--r-- 2,147 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright 2024 Red Hat Inc.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Carlos Garnacho <carlosg@gnome.org>
 */

#include "fuzz.h"

#define MAX_SIZE 800 * 1024

int
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
{
	static TrackerSparqlConnection *conn = NULL;
	TrackerSparqlStatement *stmt;
	unsigned char *nul_terminated_data = NULL;

	sqlite3_config (SQLITE_CONFIG_LOOKASIDE, 0, 0);

	fuzz_set_logging_func ();

	if (size > MAX_SIZE)
		return 0;

	if (!conn) {
		GFile *ontology;

		/* Point to empty ontology */
		ontology = g_file_new_for_uri ("resource:///");
		conn = tracker_sparql_connection_new (TRACKER_SPARQL_CONNECTION_FLAGS_SPARQL_STRICT,
		                                      NULL,
		                                      ontology,
		                                      NULL, NULL);
		g_clear_object (&ontology);
	}

	nul_terminated_data = (unsigned char *) g_strndup ((const gchar *) data, size);
	stmt = tracker_sparql_connection_query_statement (conn,
	                                                  (const gchar *) nul_terminated_data,
	                                                  NULL, NULL);

	g_clear_object (&stmt);

	stmt = tracker_sparql_connection_update_statement (conn,
	                                                   (const gchar *) nul_terminated_data,
	                                                   NULL, NULL);
	g_clear_object (&stmt);
	g_free (nul_terminated_data);

	return 0;
}