/src/pacemaker/lib/cib/fuzzers/cib_file_fuzzer.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2024 the Pacemaker project contributors |
3 | | * |
4 | | * The version control history for this file may have further details. |
5 | | * |
6 | | * This source code is licensed under the GNU Lesser General Public License |
7 | | * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. |
8 | | */ |
9 | | |
10 | | #include <crm_internal.h> |
11 | | |
12 | | #include <stdint.h> |
13 | | #include <stdio.h> |
14 | | #include <stdlib.h> |
15 | | |
16 | | #include <crm/cib.h> |
17 | | |
18 | | int |
19 | | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
20 | 3.93k | { |
21 | 3.93k | char *filename = NULL; |
22 | 3.93k | int fd = 0; |
23 | 3.93k | cib_t *cib = NULL; |
24 | | |
25 | | // Have at least some data |
26 | 3.93k | if (size < 5) { |
27 | 16 | return -1; // Do not add input to testing corpus |
28 | 16 | } |
29 | | |
30 | 3.92k | filename = pcmk__assert_alloc(size + 1, sizeof(char)); |
31 | 3.92k | memcpy(filename, data, size); |
32 | 3.92k | filename[size] = '\0'; |
33 | | |
34 | 3.92k | cib = cib_file_new(filename); |
35 | | |
36 | 3.92k | cib_delete(cib); |
37 | 3.92k | free(filename); |
38 | 3.92k | return 0; |
39 | 3.93k | } |