/src/pacemaker/lib/common/fuzzers/strings_fuzzer.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2024-2026 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 <stdlib.h> |
14 | | #include <stdio.h> |
15 | | #include <strings.h> |
16 | | #include <glib.h> |
17 | | |
18 | | #include <crm/common/options.h> |
19 | | #include <crm/common/util.h> |
20 | | |
21 | | int |
22 | | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
23 | 1.43k | { |
24 | 1.43k | char *ns = NULL; |
25 | 1.43k | unsigned int res = 0; |
26 | 1.43k | long long msec = 0LL; |
27 | | |
28 | 1.43k | if (size < 10) { |
29 | 16 | return -1; // Do not add input to testing corpus |
30 | 16 | } |
31 | 1.41k | ns = pcmk__assert_alloc(size + 1, sizeof(char)); |
32 | 1.41k | memcpy(ns, data, size); |
33 | 1.41k | ns[size] = '\0'; |
34 | | |
35 | 1.41k | pcmk__numeric_strcasecmp(ns, ns); |
36 | 1.41k | pcmk_parse_interval_spec(ns, &res); |
37 | 1.41k | pcmk__parse_ms(ns, &msec); |
38 | | |
39 | 1.41k | free(ns); |
40 | 1.41k | return 0; |
41 | 1.43k | } |