]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
fix fuzzing
authorAydın Mercan <aydin@isc.org>
Fri, 3 Oct 2025 12:37:01 +0000 (15:37 +0300)
committerAydın Mercan <aydin@isc.org>
Fri, 24 Oct 2025 11:35:28 +0000 (14:35 +0300)
The fuzzing binary builds have been fixed and now is run as a part of
the test suite for sanity checks.

The `oss-fuzz` backend has been made functional with the addition of the
`oss-fuzz-args` option. It allows the setup script to pass the
LIB_FUZZING_ENGINE environment variable to meson.

fuzz/meson.build
meson.build
meson_options.txt
util/pairwise-construct.jq

index 43e1251bd738c2d1c410d64fdb3c8bdeffa2601b..a7d7d1b4689fcee37b04215a29eed6bb41d960f0 100644 (file)
@@ -9,7 +9,7 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-if fuzz_opt.enabled()
+if fuzzing_opt.disabled()
     subdir_done()
 endif
 
index f99d65f2c6892a1032cbd1449d1d2b0c7d9ac5b4..3683e3c81cf5ce820ea778eee3155bc6bc0cba2b 100644 (file)
@@ -43,6 +43,7 @@ endif
 developer_mode = get_option('developer').enabled()
 
 c_std = get_option('c_std')
+lundef = get_option('b_lundef')
 optimization = get_option('optimization')
 sanitizer = get_option('b_sanitize')
 meson_lto = get_option('b_lto')
@@ -55,8 +56,8 @@ dnstap_opt = get_option('dnstap')
 doc_opt = get_option('doc')
 doh_opt = get_option('doh')
 fips_opt = get_option('fips')
-fuzz_opt = get_option('fuzzing')
-fuzz_backend_opt = get_option('fuzzing-backend')
+fuzzing_backend_opt = get_option('fuzzing-backend')
+fuzzing_opt = get_option('fuzzing')
 geoip_opt = get_option('geoip')
 gssapi_opt = get_option('gssapi')
 idn_opt = get_option('idn')
@@ -66,6 +67,7 @@ line_opt = get_option('line')
 lmdb_opt = get_option('lmdb')
 locktype_opt = get_option('locktype')
 named_lto_opt = get_option('named-lto')
+oss_fuzz_args_opt = get_option('oss-fuzz-args')
 stats_json_opt = get_option('stats-json')
 stats_xml_opt = get_option('stats-xml')
 tracing_opt = get_option('tracing')
@@ -405,21 +407,34 @@ endif
 ## Fuzzing
 config.set_quoted('FUZZDIR', meson.project_source_root() / 'fuzz')
 
-fuzz_link_args = []
-if fuzz_opt.enabled()
-    if fuzz_backed_opt != 'none'
-        if get_option('b_lundef') != false
-            warning('fuzzing will fail to build properly without -Db_lundef=false')
-        endif
+if fuzzing_backend_opt != 'none'
+    assert(
+        fuzzing_opt.allowed(),
+        'fuzzing backend cannot be specified while fuzzing is disabled',
+    )
 
-        if fuzz_opt == 'afl'
-        elif fuzz_opt == 'libfuzzer'
-            config.set('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1)
-            fuzz_link_args += '-fsanitize=fuzzer,address,undefined'
-            add_project_link_arguments('-fsanitize=address,undefined', language: 'c')
-            add_project_arguments('-fsanitize=fuzzer-no-link,address,undefined', language: 'c')
-        endif
-    endif
+    assert(
+        not (cc.get_id() == 'clang' and lundef != false),
+        'fuzzing will not build properly without -Db_lundef=false',
+    )
+endif
+
+fuzz_link_args = []
+if fuzzing_backend_opt == 'afl'
+    config.set('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1)
+    config.set('ENABLE_AFL', 1)
+elif fuzzing_backend_opt == 'libfuzzer'
+    config.set('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1)
+    fuzz_link_args += '-fsanitize=fuzzer,address,undefined'
+    add_project_link_arguments('-fsanitize=address,undefined', language: 'c')
+    add_project_arguments('-fsanitize=fuzzer-no-link,address,undefined', language: 'c')
+elif fuzzing_backend_opt == 'oss-fuzz'
+    config.set('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1)
+    assert(
+        oss_fuzz_args_opt != '',
+        '-Doss-fuzz-args must be set when using the "oss-fuzz" fuzzing backend',
+    )
+    fuzz_link_args += oss_fuzz_args_opt
 endif
 
 ## Architecture
@@ -1726,7 +1741,7 @@ subdir('doc')
 subdir('tests')
 
 foreach name, sources : fuzz_binaries
-    executable(
+    fuzz_bin = executable(
         name,
         sources,
         export_dynamic: true,
@@ -1740,6 +1755,14 @@ foreach name, sources : fuzz_binaries
             libtest_dep,
         ],
     )
+
+    test(
+        name,
+        fuzz_bin,
+        protocol: 'exitcode',
+        suite: 'fuzz',
+        timeout: 60,
+    )
 endforeach
 
 foreach name, sources : system_test_binaries
index 70a77f312866673466c774bcbf5470e3d4205fe1..0fac926a4a9beec9319256ada049a5471bcc8437 100644 (file)
@@ -175,6 +175,12 @@ option(
     description: 'Fuzzing backend (backend none with -Dfuzzing=enabled only compiles the binary)',
 )
 
+option(
+    'oss-fuzz-args',
+    type: 'string',
+    description: 'Fuzzing linking arguments for OSS-Fuzz',
+)
+
 option(
     'trace-logging',
     type: 'array',
index 3007880137c7e0accecacac06c49b372f117af3e..44c6553c520f7059fbf9cff8b8a9f6161c9f1c1e 100755 (executable)
@@ -12,7 +12,7 @@
 # information regarding copyright ownership.
 
 .[]
-    | select((.section == "user") and (.name | IN("rcu-flavor", "geoip", "fuzzing", "doh", "fips", "trace-logging") | not))
+    | select((.section == "user") and (.name | IN("rcu-flavor", "geoip", "fuzzing", "doh", "fuzzing-backend", "oss-fuzz-args", "fips", "trace-logging") | not))
     | ["\(.name):", "-D\(.name)=\(.choices[]),"]
     | join(" ")
     | .[:-1]