2020-11-09 13:23:58 +09:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2018-01-19 17:54:30 +11:00
2022-10-06 16:48:01 +02: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 11:33:12 +02:00
sanitize_address_undefined = custom_target (
'sanitize-address-undefined-fuzzers' ,
output : 'sanitize-address-undefined-fuzzers' ,
2018-01-19 17:54:30 +11:00
command : [ meson_build_sh ,
2019-02-27 11:19:07 -05:00
project_source_root ,
2018-01-19 17:54:30 +11: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 12:51:44 +01: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 12:51:44 +01:00
) ,
2018-10-04 04:52:44 +09:00
' ' . join ( cc . cmd_array ( ) ) ,
2018-10-10 11:50:57 +02:00
cxx_cmd ] )
2018-01-19 17:54:30 +11:00
2022-10-06 19:06:08 +02:00
fuzz_sanitizers = [ [ 'address,undefined' , sanitize_address_undefined ] ]
fuzz_testsdir = 'test/fuzz'
2018-03-14 14:27:04 +01:00
2023-03-01 22:54:06 +01:00
if git . found ( ) and fs . is_dir ( project_source_root / '.git' )
2021-05-14 14:16:17 +02:00
out = run_command ( env , '-u' , 'GIT_WORK_TREE' ,
git , '--git-dir=@0@/.git' . format ( project_source_root ) ,
2022-10-06 19:06:08 +02:00
'ls-files' , ':/@0@/*/*' . format ( fuzz_testsdir ) ,
2022-01-11 10:56:22 +01:00
check : true )
2018-08-10 17:15:05 +02:00
else
2022-10-06 19:06:08 +02:00
out = run_command ( sh , '-c' , 'cd "@0@"; echo @1@/*/*' . format ( project_source_root , fuzz_testsdir ) , check : true )
2018-08-10 17:15:05 +02:00
endif
2022-10-06 16:48:01 +02: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 17:15:05 +02: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 19:06:08 +02:00
if p . contains ( '\\' )
continue
2018-08-10 17:15:05 +02:00
endif
2023-06-14 16:05:52 +02:00
fuzzer = fs . name ( fs . parent ( p ) )
fuzz_in = fs . name ( p )
2022-10-06 19:06:08 +02:00
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 16:48:01 +02:00
l + = [ [ fuzz_testsdir , fuzz_in ] ]
2022-10-06 19:06:08 +02:00
fuzz_regression_tests + = { fuzzer : l }
2018-08-10 17:15:05 +02:00
endforeach