/src/systemd/src/fuzz/fuzz-env-file.c
Line | Count | Source |
1 | | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | | |
3 | | #include <stdio.h> |
4 | | |
5 | | #include "alloc-util.h" |
6 | | #include "env-file.h" |
7 | | #include "fileio.h" |
8 | | #include "fd-util.h" |
9 | | #include "fuzz.h" |
10 | | #include "strv.h" |
11 | | |
12 | 1.31k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
13 | 1.31k | _cleanup_fclose_ FILE *f = NULL; |
14 | 1.31k | _cleanup_strv_free_ char **rl = NULL, **rlp = NULL; |
15 | 1.31k | |
16 | 1.31k | if (size == 0 || size > 65535) |
17 | 8 | return 0; |
18 | 1.30k | |
19 | 1.30k | f = fmemopen_unlocked((char*) data, size, "re"); |
20 | 1.30k | assert_se(f); |
21 | 1.30k | |
22 | 1.30k | /* We don't want to fill the logs with messages about parse errors. |
23 | 1.30k | * Disable most logging if not running standalone */ |
24 | 1.30k | if (!getenv("SYSTEMD_LOG_LEVEL")) |
25 | 1.30k | log_set_max_level(LOG_CRIT); |
26 | 1.30k | |
27 | 1.30k | (void) load_env_file(f, NULL, &rl); |
28 | 1.30k | assert_se(fseek(f, 0, SEEK_SET) == 0); |
29 | 1.30k | (void) load_env_file_pairs(f, NULL, &rlp); |
30 | 1.30k | |
31 | 1.30k | return 0; |
32 | 1.30k | } |