`standalone_fuzz_target_runner.cc`, which does no fuzzing but makes it easy
to check a given test file, or just that the fuzzing targets can be built properly.
-This behaviour can be changed via the `LIB_FUZZING_ENGINE` variable, for example
-by setting it to `-lFuzzer`, building with clang by setting `CC=clang CXX=clang++`
-before running the `configure` and adding `-fsanitize=fuzzer-no-link` to `CFLAGS`
-and `CXXFLAGS`. Doing so instructs the compiler to instrument the code for
-efficient fuzzing but not to link directly with `-lFuzzer`, which would make
-the compilation tests done during the configure phase fail.
+This behaviour can be changed via:
+- either the `LIB_FUZZING_ENGINE` variable when building with `./configure`
+- or the `-Dfuzzer_ldflags` option when building with `meson`
+
+For example, setting `LIB_FUZZING_ENGINE` to `-lFuzzer`, then building with clang
+by setting `CC=clang CXX=clang++` before running the `configure`, and adding
+`-fsanitize=fuzzer-no-link` to `CFLAGS` and `CXXFLAGS`, instructs the compiler
+to instrument the code for efficient fuzzing but not to link directly with
+`-lFuzzer`, which would make the compilation tests done during the configure phase fail.
Sanitizers
----------
make -C pdns -j2 fuzz_targets
```
+or, if you are using `meson` to build the authoritative server instead of `./configure`:
+
+```
+env CC=clang CXX=clang++ \
+ CFLAGS=-fsanitize=fuzzer-no-link CXXFLAGS=-fsanitize=fuzzer-no-link \
+ meson setup .. -Dfuzz-targets=true -Dfuzzer_ldflags=/usr/lib/clang/18/lib/linux/libclang_rt.fuzzer-x86_64.a -Db_sanitize=address,undefined
+ninja
+```
+
Now you're ready to run one of the fuzzing targets.
First, copy the starting corpus:
endif
if get_option('fuzz-targets')
+ fuzz_extra_sources = []
+ fuzzer_ldflags = []
+ # https://github.com/harfbuzz/harfbuzz/pull/2549/files
+ if get_option('fuzzer_ldflags') == ''
+ fuzz_extra_sources += src_dir / 'standalone_fuzz_target_runner.cc'
+ else
+ fuzzer_ldflags += get_option('fuzzer_ldflags')
+ endif
+
fuzz_targets = [
'moadnsparser',
'packetcache',
foreach target: fuzz_targets
source_file = src_dir / 'fuzz_' + target.underscorify() + '.cc'
tools += {
- 'fuzz-target-' + target: { 'main': source_file }
+ 'fuzz-target-' + target: { 'main': source_file,
+ 'link-args': fuzzer_ldflags,
+ 'files-extra': fuzz_extra_sources }
}
endforeach
endif
export_dynamic = 'export-dynamic' in info ? info['export-dynamic'] : false
files_extra = 'files-extra' in info ? info['files-extra'] : []
deps_extra = 'deps-extra' in info ? info['deps-extra'] : []
+ link_args = 'link-args' in info ? info['link-args'] : []
set_variable(
var_name,
config_h,
files_extra,
export_dynamic: export_dynamic,
+ link_args: link_args,
dependencies: [
deps,
libpdns_common,
option('unit-tests-backends', type: 'boolean', value: false, description: 'Build and run backend unit tests')
option('reproducible', type: 'boolean', value: false, description: 'Reproducible builds (for distro maintainers, makes debugging difficult)')
option('fuzz-targets', type: 'boolean', value: false, description: 'Enable fuzzing targets')
+option('fuzzer_ldflags', type: 'string', value: '', description: 'Linker flags used for the fuzzing targets (a path to the libFuzzer static library, for example)')
option('verbose-logging', type: 'boolean', value: false, description: 'Enable verbose logging')
option('experimental-pkcs11', type: 'feature', value: 'disabled', description: 'PKCS11 support')
option('experimental-gss-tsig', type: 'feature', value: 'disabled', description: 'GSS-TSIG support')
tools += {
'fuzz-target-dnsdistcache' : {
'main': src_dir / 'fuzz_dnsdistcache.cc',
- 'link_flags': fuzzer_ldflags,
+ 'link-args': fuzzer_ldflags,
'files-extra': fuzz_extra_sources
},
}
tools += {
'fuzz-target-xsk' : {
'main': src_dir / 'fuzz_xsk.cc',
- 'link_flags': fuzzer_ldflags,
+ 'link-args': fuzzer_ldflags,
'files-extra': fuzz_extra_sources + [
src_dir / 'dnslabeltext.cc',
src_dir / 'dnsname.cc',