Commit 73067e5c authored by Janne Grunau's avatar Janne Grunau

allocation fail fuzzer: use a static library and objcopy

oss-fuzz can not handle shared libraries. Do not build it by default.
parent a6b903fb
Pipeline #3487 passed with stages
in 4 minutes and 57 seconds
...@@ -44,23 +44,21 @@ void dav1d_setup_alloc_fail(unsigned seed, unsigned probability) { ...@@ -44,23 +44,21 @@ void dav1d_setup_alloc_fail(unsigned seed, unsigned probability) {
fail_probability = probability; fail_probability = probability;
} }
void * __real_malloc(size_t);
void * __wrap_malloc(size_t); void * __wrap_malloc(size_t);
void * __wrap_malloc(size_t sz) { void * __wrap_malloc(size_t sz) {
if (rand() < fail_probability) if (rand() < fail_probability)
return NULL; return NULL;
return __real_malloc(sz); return malloc(sz);
} }
#if defined(HAVE_POSIX_MEMALIGN) #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);
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) if (rand() < fail_probability)
return ENOMEM; return ENOMEM;
return __real_posix_memalign(memptr, alignment, size); return posix_memalign(memptr, alignment, size);
} }
#else #else
#error "HAVE_POSIX_MEMALIGN required" #error "HAVE_POSIX_MEMALIGN required"
......
...@@ -124,28 +124,29 @@ dav1d_fuzzer_mt = executable('dav1d_fuzzer_mt', ...@@ -124,28 +124,29 @@ dav1d_fuzzer_mt = executable('dav1d_fuzzer_mt',
dependencies : [thread_dependency], dependencies : [thread_dependency],
) )
if (cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args) and objcopy = find_program('objcopy',
cc.has_link_argument('-Wl,-wrap,malloc') and not get_option('b_lto')) required: false)
if (objcopy.found() and
alloc_fail = shared_library('alloc_fail', not get_option('b_lto') and
files('libfuzzer/alloc_fail.c'), get_option('default_library') == 'static' and
libdav1d_nasm_objs_if_needed, cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args))
objects: [
libdav1d.extract_all_objects(recursive: true), libdav1d_af = custom_target('libdav1d_af',
], input: libdav1d,
include_directories: dav1d_inc_dirs, output: 'libdav1d_af.a',
c_args : [stackalign_flag], depends: libdav1d,
link_args: ['-Wl,-wrap,malloc', '-Wl,-wrap,posix_memalign'], command: [objcopy,
dependencies : [thread_dependency], '--redefine-sym', 'malloc=__wrap_malloc',
) '--redefine-sym', 'posix_memalign=__wrap_posix_memalign',
'@INPUT@', '@OUTPUT@'])
dav1d_fuzzer_mem = executable('dav1d_fuzzer_mem', dav1d_fuzzer_mem = executable('dav1d_fuzzer_mem',
dav1d_fuzzer_sources, dav1d_fuzzer_sources + ['libfuzzer/alloc_fail.c'],
include_directories: dav1d_inc_dirs, include_directories: dav1d_inc_dirs,
c_args: [stackalign_flag, stackrealign_flag, '-DDAV1D_ALLOC_FAIL'], c_args: [stackalign_flag, stackrealign_flag, '-DDAV1D_ALLOC_FAIL'],
link_args: fuzzer_ldflags, link_args: fuzzer_ldflags + [join_paths(libdav1d_af.full_path())],
link_with : [alloc_fail], link_depends: libdav1d_af,
build_by_default: true, build_by_default: false,
dependencies : [thread_dependency], dependencies : [thread_dependency],
) )
endif endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment