2020-11-09 07:23:58 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2018-01-19 09:54:30 +03:00
2022-10-06 17:48:01 +03:00
generate_directives_py = find_program ( 'generate-directives.py' )
fuzz_generated_in_dir = meson . current_build_dir ( )
fuzz_generated_directives = [ ]
directives = [ [ 'fuzz-network-parser_directives' , 'src/network/networkd-network-gperf.gperf' ] ,
[ 'fuzz-netdev-parser_directives.netdev' , 'src/network/netdev/netdev-gperf.gperf' ] ,
[ 'fuzz-link-parser_directives.link' , 'src/udev/net/link-config-gperf.gperf' ] ,
]
foreach tuple : directives
fuzz_generated_directives + = custom_target (
tuple [ 0 ] ,
output : tuple [ 0 ] ,
command : [ generate_directives_py , files ( project_source_root / tuple [ 1 ] ) ] ,
capture : true )
endforeach
foreach section : [ 'Automount' , 'Mount' , 'Path' , 'Scope' , 'Service' , 'Slice' , 'Socket' , 'Swap' , 'Timer' ]
unit_type = section . to_lower ( )
sec_rx = section == 'Service' ? '(Service|Unit|Install)' : section
fuzz_generated_directives + = custom_target (
'fuzz-unit-file_directives.@0@' . format ( unit_type ) ,
output : 'fuzz-unit-file_directives.@0@' . format ( unit_type ) ,
command : [ generate_directives_py , load_fragment_gperf_gperf , sec_rx , unit_type ] ,
capture : true )
endforeach
############################################################
2020-05-20 12:33:12 +03:00
sanitize_address_undefined = custom_target (
'sanitize-address-undefined-fuzzers' ,
output : 'sanitize-address-undefined-fuzzers' ,
2018-01-19 09:54:30 +03:00
command : [ meson_build_sh ,
2019-02-27 19:19:07 +03:00
project_source_root ,
2018-01-19 09:54:30 +03:00
'@OUTPUT@' ,
'fuzzers' ,
2022-02-22 20:47:48 +03: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 14:51:44 +03:00
get_option ( 'optimization' ) ,
2022-02-03 05:22:53 +03:00
get_option ( 'werror' ) ? '--werror' : '' ,
2022-02-22 20:47:48 +03:00
'-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION' ,
get_option ( 'skip-deps' )
2022-01-04 14:51:44 +03:00
) ,
2018-10-03 22:52:44 +03:00
' ' . join ( cc . cmd_array ( ) ) ,
2018-10-10 12:50:57 +03:00
cxx_cmd ] )
2018-01-19 09:54:30 +03:00
2022-10-06 20:06:08 +03:00
fuzz_sanitizers = [ [ 'address,undefined' , sanitize_address_undefined ] ]
fuzz_testsdir = 'test/fuzz'
2018-03-14 16:27:04 +03:00
2023-03-02 00:54:06 +03:00
if git . found ( ) and fs . is_dir ( project_source_root / '.git' )
2021-05-14 15:16:17 +03:00
out = run_command ( env , '-u' , 'GIT_WORK_TREE' ,
git , '--git-dir=@0@/.git' . format ( project_source_root ) ,
2022-10-06 20:06:08 +03:00
'ls-files' , ':/@0@/*/*' . format ( fuzz_testsdir ) ,
2022-01-11 12:56:22 +03:00
check : true )
2018-08-10 18:15:05 +03:00
else
2022-10-06 20:06:08 +03:00
out = run_command ( sh , '-c' , 'cd "@0@"; echo @1@/*/*' . format ( project_source_root , fuzz_testsdir ) , check : true )
2018-08-10 18:15:05 +03:00
endif
2022-10-06 17:48:01 +03:00
# Fuzz inputs that we generate (see above fuzz_generated_directives)
fuzz_regression_tests = {
'fuzz-link-parser' : [ [ '' , 'directives.link' ] ] ,
'fuzz-netdev-parser' : [ [ '' , 'directives.netdev' ] ] ,
'fuzz-network-parser' : [ [ '' , 'directives' ] ] ,
'fuzz-unit-file' : [ [ '' , 'directives.automount' ] ,
[ '' , 'directives.mount' ] ,
[ '' , 'directives.path' ] ,
[ '' , 'directives.scope' ] ,
[ '' , 'directives.service' ] ,
[ '' , 'directives.slice' ] ,
[ '' , 'directives.socket' ] ,
[ '' , 'directives.swap' ] ,
[ '' , 'directives.timer' ] ] }
# Add crafted fuzz inputs we have in the repo
2018-08-10 18:15:05 +03: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 20:06:08 +03:00
if p . contains ( '\\' )
continue
2018-08-10 18:15:05 +03:00
endif
2022-10-06 20:06:08 +03:00
fuzzer = p . split ( '/' ) [ - 2 ]
fuzz_in = p . split ( '/' ) [ - 1 ]
if fuzzer not in fuzz_regression_tests
fuzz_regression_tests + = { fuzzer : [ ] }
endif
# Meson parser provision for: fuzz_regression_tests[fuzzer] += [fuzz_in]
l = fuzz_regression_tests [ fuzzer ]
2022-10-06 17:48:01 +03:00
l + = [ [ fuzz_testsdir , fuzz_in ] ]
2022-10-06 20:06:08 +03:00
fuzz_regression_tests + = { fuzzer : l }
2018-08-10 18:15:05 +03:00
endforeach