/src/tinysparql/fuzzing/fuzz_rdf_trig.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 | 45.6k | #define MAX_SIZE 800 * 1024 |
25 | | |
26 | | int |
27 | | LLVMFuzzerTestOneInput (const unsigned char *data, size_t size) |
28 | 45.6k | { |
29 | 45.6k | static TrackerSparqlConnection *conn = NULL; |
30 | 45.6k | TrackerBatch *batch; |
31 | 45.6k | GInputStream *istream; |
32 | | |
33 | 45.6k | sqlite3_config (SQLITE_CONFIG_LOOKASIDE, 0, 0); |
34 | | |
35 | 45.6k | fuzz_set_logging_func (); |
36 | | |
37 | 45.6k | if (size > MAX_SIZE) |
38 | 4 | return 0; |
39 | | |
40 | 45.6k | istream = g_memory_input_stream_new_from_data (data, size, NULL); |
41 | | |
42 | 45.6k | if (!conn) { |
43 | 7.66k | GFile *ontology; |
44 | | |
45 | | /* Point to empty ontology */ |
46 | 7.66k | ontology = g_file_new_for_uri ("resource:///"); |
47 | 7.66k | conn = tracker_sparql_connection_new (TRACKER_SPARQL_CONNECTION_FLAGS_NONE, |
48 | 7.66k | NULL, |
49 | 7.66k | ontology, |
50 | 7.66k | NULL, NULL); |
51 | 7.66k | g_clear_object (&ontology); |
52 | 7.66k | } |
53 | | |
54 | 45.6k | batch = tracker_sparql_connection_create_batch (conn); |
55 | | |
56 | 45.6k | tracker_batch_add_rdf (batch, |
57 | 45.6k | TRACKER_DESERIALIZE_FLAGS_NONE, |
58 | 45.6k | TRACKER_RDF_FORMAT_TRIG, |
59 | 45.6k | NULL, |
60 | 45.6k | istream); |
61 | | |
62 | 45.6k | if (tracker_batch_execute (batch, NULL, NULL)) |
63 | 45.6k | g_clear_object (&conn); |
64 | | |
65 | 45.6k | g_clear_object (&batch); |
66 | 45.6k | g_clear_object (&istream); |
67 | | |
68 | 45.6k | return 0; |
69 | 45.6k | } |