mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
Currently, when fuzzers are enabled, we run meson from within meson to build the fuzzer executables with sanitizers. The idea is that we can build the fuzzers with different kinds of sanitizers independently from the main build. The issue with this setup is that we don't actually make use of it. We only build the fuzzers with one set of sanitizers (address,undefined) so we're adding a bunch of extra complexity without any benefit as we can just setup the top level meson build with these sanitizers and get the same result. The other issue with this setup is that we don't pass on all the options passed to the top level meson build to the nested meson build. The only things we pass on are extra compiler arguments and the value of the auto_features option, but none of the individual feature options if overridden are passed on, which can lead to very hard to debug issues as an option enabled in the top level build is not enabled in the nested build. Since we're not getting anything useful out of this setup, let's simplify and get rid of the nested meson build. Instead, sanitizers should be enabled for the top level meson.build. This currently didn't work as we were overriding the sanitizers passed to the meson build with the fuzzer sanitizer, so we fix that as well by making sure we combine the fuzzer sanitizer with the ones passed in by the user. We also drop support for looking up libFuzzer as a separate library as it has been shipped builtin in clang since clang 6.0, so we can assume that -fsanitize=fuzzer is available. To make sure we still run the fuzzing tests, we enable the fuzz-tests option by default now to make sure they still always run (without instrumentation unless one of llvm-fuzz or oss-fuzz is enabled).
66 lines
2.4 KiB
Meson
66 lines
2.4 KiB
Meson
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
generate_directives_py = find_program('generate-directives.py')
|
|
|
|
fuzz_regression_tests = {}
|
|
|
|
directives = [['fuzz-network-parser', 'directives.network', networkd_network_gperf_gperf],
|
|
['fuzz-netdev-parser', 'directives.netdev', networkd_netdev_gperf_gperf],
|
|
['fuzz-link-parser', 'directives.link', udev_link_gperf_gperf],
|
|
]
|
|
|
|
foreach tuple : directives
|
|
directive = custom_target(
|
|
tuple[1],
|
|
output: tuple[1],
|
|
command: [generate_directives_py, tuple[2]],
|
|
capture: true)
|
|
|
|
dict = { 'directives' : [directive] }
|
|
fuzz_regression_tests += { tuple[0] : dict }
|
|
endforeach
|
|
|
|
unit_directives = []
|
|
foreach section : ['Automount', 'Mount', 'Path', 'Scope', 'Service', 'Slice', 'Socket', 'Swap', 'Timer']
|
|
unit_type = section.to_lower()
|
|
sec_rx = section == 'Service' ? '(Service|Unit|Install)' : section
|
|
name = 'directives.@0@'.format(unit_type)
|
|
unit_directives += custom_target(
|
|
name,
|
|
output: name,
|
|
command: [generate_directives_py, load_fragment_gperf_gperf, sec_rx, unit_type],
|
|
capture: true)
|
|
endforeach
|
|
dict = { 'directives' : unit_directives }
|
|
fuzz_regression_tests += { 'fuzz-unit-file' : dict }
|
|
|
|
############################################################
|
|
|
|
fuzz_testsdir = 'test/fuzz'
|
|
|
|
if git.found() and fs.is_dir(meson.project_source_root() / '.git')
|
|
out = run_command(env, '-u', 'GIT_WORK_TREE',
|
|
git, '--git-dir=@0@/.git'.format(meson.project_source_root()),
|
|
'ls-files', ':/@0@/*/*'.format(fuzz_testsdir),
|
|
check: true)
|
|
else
|
|
out = run_command(sh, '-c', 'cd "@0@"; echo @1@/*/*'.format(meson.project_source_root(), fuzz_testsdir), check: true)
|
|
endif
|
|
|
|
# Add crafted fuzz inputs we have in the repo
|
|
foreach p : out.stdout().split()
|
|
# Remove the last entry which is ''.
|
|
#
|
|
# Also, backslashes get mangled, so skip test. See
|
|
# https://github.com/mesonbuild/meson/issues/1564.
|
|
if p.contains('\\')
|
|
continue
|
|
endif
|
|
fuzzer = fs.name(fs.parent(p))
|
|
fuzz_in = fs.name(p)
|
|
|
|
dict = fuzz_regression_tests.get(fuzzer, {})
|
|
dict += { 'files' : dict.get('files', []) + files(fuzzer / fuzz_in) }
|
|
fuzz_regression_tests += { fuzzer : dict }
|
|
endforeach
|