Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2023 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include <stdint.h> |
14 | | #include <stdio.h> |
15 | | #include <stdlib.h> |
16 | | |
17 | | #include "cJSON.h" |
18 | | #include "loader.h" |
19 | | |
20 | | /* |
21 | | * Targets the custom version of cJson. |
22 | | */ |
23 | 1.40k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
24 | 1.40k | char filename[256]; |
25 | 1.40k | sprintf(filename, "/tmp/libfuzzer.%d", getpid()); |
26 | | |
27 | 1.40k | FILE *fp = fopen(filename, "wb"); |
28 | 1.40k | if (!fp) { |
29 | 0 | return 0; |
30 | 0 | } |
31 | 1.40k | fwrite(data, size, 1, fp); |
32 | 1.40k | fclose(fp); |
33 | | |
34 | 1.40k | cJSON *json = NULL; |
35 | 1.40k | loader_get_json(NULL, filename, &json); |
36 | 1.40k | if (json != NULL) { |
37 | 718 | free(json); |
38 | 718 | } |
39 | 1.40k | unlink(filename); |
40 | | |
41 | 1.40k | return 0; |
42 | 1.40k | } |