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