mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
Merge pull request #7933 from keszybz/fuzz-regression
test: add fuzzer regression testing
This commit is contained in:
commit
4c0d481095
3
HACKING
3
HACKING
@ -102,6 +102,9 @@ commands like this:
|
||||
python infra/helper.py build_fuzzers --sanitizer memory systemd ../systemd
|
||||
python infra/helper.py run_fuzzer systemd fuzz-foo
|
||||
|
||||
If you find a bug that impacts the security of systemd, please follow the
|
||||
guidance in .github/CONTRIBUTING.md on how to report a security vulnerability.
|
||||
|
||||
For more details on building fuzzers and integrating with OSS-Fuzz, visit:
|
||||
|
||||
https://github.com/google/oss-fuzz/blob/master/docs/new_project_guide.md
|
||||
|
67
meson.build
67
meson.build
@ -259,6 +259,7 @@ substs.set('RC_LOCAL_SCRIPT_PATH_STOP', get_option('halt-l
|
||||
cc = meson.get_compiler('c')
|
||||
pkgconfig = import('pkgconfig')
|
||||
check_compilation_sh = find_program('tools/meson-check-compilation.sh')
|
||||
meson_build_sh = find_program('tools/meson-build.sh')
|
||||
|
||||
if get_option('tests') != 'false'
|
||||
cxx = find_program('c++', required : false)
|
||||
@ -385,6 +386,20 @@ foreach arg : ['-Wl,-z,relro',
|
||||
endif
|
||||
endforeach
|
||||
|
||||
# Check if various sanitizers are supported
|
||||
sanitizers = []
|
||||
foreach arg : ['address']
|
||||
|
||||
have = run_command(check_compilation_sh,
|
||||
cc.cmd_array(), '-x', 'c',
|
||||
'-fsanitize=@0@'.format(arg),
|
||||
'-include', link_test_c).returncode() == 0
|
||||
message('@0@ sanitizer supported: @1@'.format(arg, have ? 'yes' : 'no'))
|
||||
if have
|
||||
sanitizers += arg
|
||||
endif
|
||||
endforeach
|
||||
|
||||
if get_option('buildtype') != 'debug'
|
||||
foreach arg : ['-ffunction-sections',
|
||||
'-fdata-sections']
|
||||
@ -517,6 +532,7 @@ awk = find_program('awk')
|
||||
m4 = find_program('m4')
|
||||
stat = find_program('stat')
|
||||
git = find_program('git', required : false)
|
||||
env = find_program('env')
|
||||
|
||||
meson_make_symlink = meson.source_root() + '/tools/meson-make-symlink.sh'
|
||||
mkdir_p = 'mkdir -p $DESTDIR/@0@'
|
||||
@ -1202,10 +1218,11 @@ endforeach
|
||||
|
||||
want_tests = get_option('tests')
|
||||
install_tests = get_option('install-tests')
|
||||
slow_tests = get_option('slow-tests')
|
||||
tests = []
|
||||
fuzzers = []
|
||||
|
||||
conf.set10('SYSTEMD_SLOW_TESTS_DEFAULT', get_option('slow-tests'))
|
||||
conf.set10('SYSTEMD_SLOW_TESTS_DEFAULT', slow_tests)
|
||||
|
||||
#####################################################################
|
||||
|
||||
@ -2573,6 +2590,50 @@ endforeach
|
||||
|
||||
############################################################
|
||||
|
||||
prev = ''
|
||||
foreach p : fuzz_regression_tests
|
||||
a = p.split('/')[-3]
|
||||
b = p.split('/')[-2]
|
||||
c = p.split('/')[-1]
|
||||
|
||||
if a == 'address'
|
||||
build = sanitize_address
|
||||
else
|
||||
error('unknown sanitizer @0@'.format(a))
|
||||
endif
|
||||
|
||||
name = '@1@:@0@'.format(a, b)
|
||||
|
||||
if name != prev
|
||||
if want_tests == 'false'
|
||||
message('Not compiling @0@ because tests is set to false'.format(name))
|
||||
elif not sanitizers.contains(a)
|
||||
message('Not compiling @0@ because @1@ sanitizer is not available'.format(name, a))
|
||||
elif slow_tests
|
||||
exe = custom_target(
|
||||
name,
|
||||
output : name,
|
||||
depends : build,
|
||||
command : [env, 'ln', '-fs',
|
||||
join_paths(build.full_path(), b),
|
||||
'@OUTPUT@'],
|
||||
build_by_default : true)
|
||||
else
|
||||
message('Not compiling @0@ because slow-tests is set to false'.format(name))
|
||||
endif
|
||||
endif
|
||||
prev = name
|
||||
|
||||
if want_tests != 'false' and slow_tests
|
||||
test(c, env, args : [exe.full_path(),
|
||||
join_paths(meson.source_root(),
|
||||
'test/fuzz-regressions',
|
||||
p)])
|
||||
endif
|
||||
endforeach
|
||||
|
||||
############################################################
|
||||
|
||||
if git.found()
|
||||
all_files = run_command(
|
||||
git,
|
||||
@ -2584,11 +2645,11 @@ if git.found()
|
||||
custom_target(
|
||||
'tags',
|
||||
output : 'tags',
|
||||
command : ['env', 'etags', '-o', '@0@/TAGS'.format(meson.current_source_dir())] + all_files)
|
||||
command : [env, 'etags', '-o', '@0@/TAGS'.format(meson.current_source_dir())] + all_files)
|
||||
custom_target(
|
||||
'ctags',
|
||||
output : 'ctags',
|
||||
command : ['env', 'ctags', '-o', '@0@/tags'.format(meson.current_source_dir())] + all_files)
|
||||
command : [env, 'ctags', '-o', '@0@/tags'.format(meson.current_source_dir())] + all_files)
|
||||
endif
|
||||
|
||||
if git.found()
|
||||
|
BIN
test/fuzz-regressions/address/fuzz-dns-packet/issue-7888
Normal file
BIN
test/fuzz-regressions/address/fuzz-dns-packet/issue-7888
Normal file
Binary file not shown.
BIN
test/fuzz-regressions/address/fuzz-dns-packet/oss-fuzz-5465
Normal file
BIN
test/fuzz-regressions/address/fuzz-dns-packet/oss-fuzz-5465
Normal file
Binary file not shown.
30
test/fuzz-regressions/meson.build
Normal file
30
test/fuzz-regressions/meson.build
Normal file
@ -0,0 +1,30 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1+
|
||||
#
|
||||
# Copyright 2018 Zbigniew Jędrzejewski-Szmek
|
||||
#
|
||||
# systemd is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# systemd is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
sanitize_address = custom_target(
|
||||
'sanitize-address-fuzzers',
|
||||
output : 'sanitize-address-fuzzers',
|
||||
command : [meson_build_sh,
|
||||
meson.source_root(),
|
||||
'@OUTPUT@',
|
||||
'fuzzers',
|
||||
'-Db_lundef=false -Db_sanitize=address'])
|
||||
|
||||
fuzz_regression_tests = '''
|
||||
address/fuzz-dns-packet/oss-fuzz-5465
|
||||
address/fuzz-dns-packet/issue-7888
|
||||
'''.split()
|
@ -228,3 +228,5 @@ if conf.get('ENABLE_HWDB') == 1
|
||||
hwdb_test_sh,
|
||||
timeout : 90)
|
||||
endif
|
||||
|
||||
subdir('fuzz-regressions')
|
||||
|
10
tools/meson-build.sh
Executable file
10
tools/meson-build.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
set -eux
|
||||
|
||||
src="$1"
|
||||
dst="$2"
|
||||
target="$3"
|
||||
options="$4"
|
||||
|
||||
[ -d "$dst" ] || meson "$src" "$dst" $options
|
||||
ninja -C "$dst" "$target"
|
Loading…
Reference in New Issue
Block a user