2020-11-09 04:23:58 +00:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2018-01-19 06:54:30 +00:00
|
|
|
|
2022-10-06 14:48:01 +00:00
|
|
|
generate_directives_py = find_program('generate-directives.py')
|
|
|
|
|
2023-06-26 16:07:25 +00:00
|
|
|
fuzz_regression_tests = {}
|
2022-10-06 14:48:01 +00:00
|
|
|
|
2023-06-26 16:07:25 +00:00
|
|
|
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],
|
2022-10-06 14:48:01 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
foreach tuple : directives
|
2023-06-26 16:07:25 +00:00
|
|
|
directive = custom_target(
|
|
|
|
tuple[1],
|
|
|
|
output: tuple[1],
|
|
|
|
command: [generate_directives_py, tuple[2]],
|
2022-10-06 14:48:01 +00:00
|
|
|
capture: true)
|
2023-06-26 16:07:25 +00:00
|
|
|
|
|
|
|
dict = { 'directives' : [directive] }
|
|
|
|
fuzz_regression_tests += { tuple[0] : dict }
|
2022-10-06 14:48:01 +00:00
|
|
|
endforeach
|
|
|
|
|
2023-06-26 16:07:25 +00:00
|
|
|
unit_directives = []
|
2022-10-06 14:48:01 +00:00
|
|
|
foreach section : ['Automount', 'Mount', 'Path', 'Scope', 'Service', 'Slice', 'Socket', 'Swap', 'Timer']
|
|
|
|
unit_type = section.to_lower()
|
|
|
|
sec_rx = section == 'Service' ? '(Service|Unit|Install)' : section
|
2023-06-26 16:07:25 +00:00
|
|
|
name = 'directives.@0@'.format(unit_type)
|
|
|
|
unit_directives += custom_target(
|
|
|
|
name,
|
|
|
|
output: name,
|
2022-10-06 14:48:01 +00:00
|
|
|
command: [generate_directives_py, load_fragment_gperf_gperf, sec_rx, unit_type],
|
|
|
|
capture: true)
|
|
|
|
endforeach
|
2023-06-26 16:07:25 +00:00
|
|
|
dict = { 'directives' : unit_directives }
|
|
|
|
fuzz_regression_tests += { 'fuzz-unit-file' : dict }
|
2022-10-06 14:48:01 +00:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
|
2020-05-20 09:33:12 +00:00
|
|
|
sanitize_address_undefined = custom_target(
|
|
|
|
'sanitize-address-undefined-fuzzers',
|
|
|
|
output : 'sanitize-address-undefined-fuzzers',
|
2018-01-19 06:54:30 +00:00
|
|
|
command : [meson_build_sh,
|
2019-02-27 16:19:07 +00:00
|
|
|
project_source_root,
|
2018-01-19 06:54:30 +00:00
|
|
|
'@OUTPUT@',
|
|
|
|
'fuzzers',
|
2022-02-22 17:47:48 +00:00
|
|
|
'-Dfuzz-tests=true -Db_lundef=false -Db_sanitize=address,undefined --optimization=@0@ @1@ -Dc_args=@2@ -Dcpp_args=@2@ -Dskip-deps=@3@'.format(
|
2022-01-04 11:51:44 +00:00
|
|
|
get_option('optimization'),
|
2022-02-03 02:22:53 +00:00
|
|
|
get_option('werror') ? '--werror' : '',
|
2022-02-22 17:47:48 +00:00
|
|
|
'-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION',
|
|
|
|
get_option('skip-deps')
|
2022-01-04 11:51:44 +00:00
|
|
|
),
|
2018-10-03 19:52:44 +00:00
|
|
|
' '.join(cc.cmd_array()),
|
2018-10-10 09:50:57 +00:00
|
|
|
cxx_cmd])
|
2018-01-19 06:54:30 +00:00
|
|
|
|
2022-10-06 17:06:08 +00:00
|
|
|
fuzz_sanitizers = [['address,undefined', sanitize_address_undefined]]
|
|
|
|
fuzz_testsdir = 'test/fuzz'
|
2018-03-14 13:27:04 +00:00
|
|
|
|
2023-03-01 21:54:06 +00:00
|
|
|
if git.found() and fs.is_dir(project_source_root / '.git')
|
2021-05-14 12:16:17 +00:00
|
|
|
out = run_command(env, '-u', 'GIT_WORK_TREE',
|
|
|
|
git, '--git-dir=@0@/.git'.format(project_source_root),
|
2022-10-06 17:06:08 +00:00
|
|
|
'ls-files', ':/@0@/*/*'.format(fuzz_testsdir),
|
2022-01-11 09:56:22 +00:00
|
|
|
check: true)
|
2018-08-10 15:15:05 +00:00
|
|
|
else
|
2022-10-06 17:06:08 +00:00
|
|
|
out = run_command(sh, '-c', 'cd "@0@"; echo @1@/*/*'.format(project_source_root, fuzz_testsdir), check: true)
|
2018-08-10 15:15:05 +00:00
|
|
|
endif
|
|
|
|
|
2022-10-06 14:48:01 +00:00
|
|
|
# Add crafted fuzz inputs we have in the repo
|
2018-08-10 15:15:05 +00:00
|
|
|
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.
|
2022-10-06 17:06:08 +00:00
|
|
|
if p.contains('\\')
|
|
|
|
continue
|
2018-08-10 15:15:05 +00:00
|
|
|
endif
|
2023-06-14 14:05:52 +00:00
|
|
|
fuzzer = fs.name(fs.parent(p))
|
|
|
|
fuzz_in = fs.name(p)
|
2023-06-26 16:07:25 +00:00
|
|
|
|
|
|
|
dict = fuzz_regression_tests.get(fuzzer, {})
|
|
|
|
dict += { 'files' : dict.get('files', []) + files(fuzzer / fuzz_in) }
|
|
|
|
fuzz_regression_tests += { fuzzer : dict }
|
2018-08-10 15:15:05 +00:00
|
|
|
endforeach
|