1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "conf-parser.h"
8 #include "load-fragment.h"
9 #include "manager-dump.h"
10 #include "string-util.h"
11 #include "unit-serialize.h"
14 int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
) {
15 _cleanup_free_
char *out
= NULL
; /* out should be freed after g */
17 _cleanup_fclose_
FILE *f
= NULL
, *g
= NULL
;
18 _cleanup_free_
char *p
= NULL
;
20 _cleanup_(manager_freep
) Manager
*m
= NULL
;
28 f
= fmemopen_unlocked((char*) data
, size
, "re");
31 if (read_line(f
, LINE_MAX
, &p
) < 0)
34 t
= unit_type_from_string(p
);
38 if (!unit_vtable
[t
]->load
)
42 assert_se(offset
>= 0);
45 _cleanup_free_
char *l
= NULL
;
48 if (read_line(f
, LONG_LINE_MAX
, &l
) <= 0)
51 ll
= startswith(l
, UTF8_BYTE_ORDER_MARK
) ?: l
;
52 ll
= ll
+ strspn(ll
, WHITESPACE
);
54 if (HAS_FEATURE_MEMORY_SANITIZER
&& startswith(ll
, "ListenNetlink")) {
55 /* ListenNetlink causes a false positive in msan,
56 * let's skip this for now. */
57 log_notice("Skipping test because ListenNetlink= is present");
62 assert_se(fseek(f
, offset
, SEEK_SET
) == 0);
64 /* We don't want to fill the logs with messages about parse errors.
65 * Disable most logging if not running standalone */
66 if (!getenv("SYSTEMD_LOG_LEVEL"))
67 log_set_max_level(LOG_CRIT
);
69 assert_se(manager_new(UNIT_FILE_SYSTEM
, MANAGER_TEST_RUN_MINIMAL
, &m
) >= 0);
71 name
= strjoina("a.", unit_type_to_string(t
));
72 assert_se(unit_new_for_name(m
, unit_vtable
[t
]->object_size
, name
, &u
) >= 0);
76 UNIT_VTABLE(u
)->sections
,
77 config_item_perf_lookup
, load_fragment_gperf_lookup
,
82 g
= open_memstream_unlocked(&out
, &out_size
);
86 manager_dump(m
, g
, ">>>");