ref: 73067e5c9af6583bfc1b2da36e8162ac35035478
parent: a6b903fb6d78f1515b2c50ba17ae50ead8cf5b72
author: Janne Grunau <janne-vlc@jannau.net>
date: Tue Dec 11 16:27:37 EST 2018
allocation fail fuzzer: use a static library and objcopy oss-fuzz can not handle shared libraries. Do not build it by default.
--- a/tests/libfuzzer/alloc_fail.c
+++ b/tests/libfuzzer/alloc_fail.c
@@ -44,23 +44,21 @@
fail_probability = probability;
}
-void * __real_malloc(size_t);
void * __wrap_malloc(size_t);
void * __wrap_malloc(size_t sz) {
if (rand() < fail_probability)
return NULL;
- return __real_malloc(sz);
+ return malloc(sz);
}
#if defined(HAVE_POSIX_MEMALIGN)
-int __real_posix_memalign(void **memptr, size_t alignment, size_t size);
int __wrap_posix_memalign(void **memptr, size_t alignment, size_t size);
int __wrap_posix_memalign(void **memptr, size_t alignment, size_t size) {
if (rand() < fail_probability)
return ENOMEM;
- return __real_posix_memalign(memptr, alignment, size);
+ return posix_memalign(memptr, alignment, size);
}
#else
#error "HAVE_POSIX_MEMALIGN required"
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -124,28 +124,29 @@
dependencies : [thread_dependency],
)
-if (cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args) and
- cc.has_link_argument('-Wl,-wrap,malloc') and not get_option('b_lto'))
+objcopy = find_program('objcopy',
+ required: false)
+if (objcopy.found() and
+ not get_option('b_lto') and
+ get_option('default_library') == 'static' and
+ cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args))
- alloc_fail = shared_library('alloc_fail',
- files('libfuzzer/alloc_fail.c'),
- libdav1d_nasm_objs_if_needed,
- objects: [
- libdav1d.extract_all_objects(recursive: true),
- ],
- include_directories: dav1d_inc_dirs,
- c_args : [stackalign_flag],
- link_args: ['-Wl,-wrap,malloc', '-Wl,-wrap,posix_memalign'],
- dependencies : [thread_dependency],
- )
+ libdav1d_af = custom_target('libdav1d_af',
+ input: libdav1d,
+ output: 'libdav1d_af.a',
+ depends: libdav1d,
+ command: [objcopy,
+ '--redefine-sym', 'malloc=__wrap_malloc',
+ '--redefine-sym', 'posix_memalign=__wrap_posix_memalign',
+ '@INPUT@', '@OUTPUT@'])
dav1d_fuzzer_mem = executable('dav1d_fuzzer_mem',
- dav1d_fuzzer_sources,
+ dav1d_fuzzer_sources + ['libfuzzer/alloc_fail.c'],
include_directories: dav1d_inc_dirs,
c_args: [stackalign_flag, stackrealign_flag, '-DDAV1D_ALLOC_FAIL'],
- link_args: fuzzer_ldflags,
- link_with : [alloc_fail],
- build_by_default: true,
+ link_args: fuzzer_ldflags + [join_paths(libdav1d_af.full_path())],
+ link_depends: libdav1d_af,
+ build_by_default: false,
dependencies : [thread_dependency],
)
endif