cras: Use --enable-fuzzer to pass -DHAVE_FUZZER=1 (#9308)

https://crrev.com/c/4123919 caused -Werror,-Wmacro-redefined, due to
./configure passing -DHAVE_FUZZER=0 when not configured with
--enable-fuzzer.

To fix that:
1. Use ./configure --enable-fuzzer instead of -DHAVE_FUZZER to avoid
multiple definitions of the macro.
2. The default make rule would try to build the fuzzer itself. So
instead we selectively build just the cras binary, which is enough to
produce libcrasserver.a and libcras_rust.a.
3. The build dependency of cras_dbus_bindings.h in the Makefile is not
properly specified, so we build it manually first.

Fixes https://crbug.com/oss-fuzz/54641.
This commit is contained in:
Li-Yu Yu 2022-12-29 20:09:04 +08:00 committed by GitHub
parent d9e16a1606
commit e5e1b3db9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -25,8 +25,9 @@ cd ${SRC}/adhd/cras
./git_prepare.sh
mkdir -p ${WORK}/build && cd ${WORK}/build
export CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu"
CFLAGS="${CFLAGS} -DHAVE_FUZZER" ${SRC}/adhd/cras/configure --disable-featured
make -j$(nproc)
CFLAGS="${CFLAGS}" ${SRC}/adhd/cras/configure --enable-fuzzer --disable-featured
make -C src common/cras_dbus_bindings.h
make -C src -j$(nproc) cras
cp ${WORK}/build/src/server/rust/target/${CARGO_BUILD_TARGET}/release/libcras_rust.a /usr/local/lib
CRAS_FUZZERS="rclient_message cras_hfp_slc cras_fl_media_fuzzer"
@ -35,6 +36,7 @@ for fuzzer in ${CRAS_FUZZERS};
do
$CXX $CXXFLAGS $FUZZER_LDFLAGS \
${SRC}/adhd/cras/src/fuzz/${fuzzer}.cc -o ${OUT}/${fuzzer} \
-D HAVE_FUZZER=1 \
-I ${SRC}/adhd/cras/src/server \
-I ${SRC}/adhd/cras/src/common \
$(pkg-config --cflags dbus-1) \