[CRAS] Fix build error and build new fuzzer (#4306)

* [CRAS] Fix build error and build new fuzzer

- Fix build error by installing 1.8.x gtest and using `make install` to
  install gtest pc file for pkg-config
- Build and add new fuzzer `cras_hfp_slc`

BUG=oss-fuzz:24744

* fix the copyright

* fix the copyright

* Update Dockerfile

Co-authored-by: Max Moroz <mmoroz@chromium.org>
This commit is contained in:
b92paul 2020-08-13 04:42:51 +08:00 committed by GitHub
parent 9f088e8671
commit 6ffa47eb77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 11 deletions

View File

@ -2,6 +2,21 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# #
# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
# Defines a docker image that can build cras fuzzers. # Defines a docker image that can build cras fuzzers.
# #
FROM gcr.io/oss-fuzz-base/base-builder FROM gcr.io/oss-fuzz-base/base-builder
@ -21,6 +36,7 @@ RUN apt-get -y update && \
libsbc-dev \ libsbc-dev \
libsndfile-dev \ libsndfile-dev \
libspeexdsp-dev \ libspeexdsp-dev \
libsystemd-dev \
libtool \ libtool \
libudev-dev \ libudev-dev \
wget \ wget \
@ -34,11 +50,14 @@ RUN cd /tmp && git clone https://github.com/ndevilla/iniparser.git && \
chmod 644 /usr/local/include/dictionary.h /usr/local/include/iniparser.h && \ chmod 644 /usr/local/include/dictionary.h /usr/local/include/iniparser.h && \
chmod 644 /usr/local/lib/libiniparser.a && \ chmod 644 /usr/local/lib/libiniparser.a && \
chmod 755 /usr/local/lib/libiniparser.so.* chmod 755 /usr/local/lib/libiniparser.so.*
RUN cd /usr/src/gtest && \
cmake . && \ RUN cd /tmp && git clone https://github.com/google/googletest.git -b v1.8.x && \
make && \ cd googletest && \
chmod 644 *.a && \ mkdir build && cd build && \
cp *.a /usr/local/lib cmake .. -DBUILD_SHARED_LIBS=ON \
-DINSTALL_GTEST=ON \
-DCMAKE_INSTALL_PREFIX:PATH=/usr && \
make && make install
# Need to build and install alsa so there is a static lib. # Need to build and install alsa so there is a static lib.
RUN mkdir -p /tmp/alsa-build && cd /tmp/alsa-build && \ RUN mkdir -p /tmp/alsa-build && cd /tmp/alsa-build && \

View File

@ -3,22 +3,44 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# #
# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
# Builds fuzzers from within a container into /out/ directory. # Builds fuzzers from within a container into /out/ directory.
# Expects /src/cras to contain a cras checkout. # Expects /src/cras to contain a cras checkout.
cd ${SRC}/adhd/cras cd ${SRC}/adhd/cras
./git_prepare.sh ./git_prepare.sh
./configure --disable-dbus --disable-webrtc-apm ./configure
cargo build --release --manifest-path $SRC/adhd/cras/src/server/rust/Cargo.toml && \
cp $SRC/adhd/cras/src/server/rust/target/release/libcras_rust.a /usr/local/lib
make -j$(nproc) make -j$(nproc)
cp ${SRC}/adhd/cras/src/server/rust/target/release/libcras_rust.a /usr/local/lib
CRAS_FUZZERS="rclient_message cras_hfp_slc"
for fuzzer in ${CRAS_FUZZERS};
do
$CXX $CXXFLAGS $FUZZER_LDFLAGS \ $CXX $CXXFLAGS $FUZZER_LDFLAGS \
${SRC}/adhd/cras/src/fuzz/rclient_message.cc -o ${OUT}/rclient_message \ ${SRC}/adhd/cras/src/fuzz/${fuzzer}.cc -o ${OUT}/${fuzzer} \
-I ${SRC}/adhd/cras/src/server \ -I ${SRC}/adhd/cras/src/server \
-I ${SRC}/adhd/cras/src/common \ -I ${SRC}/adhd/cras/src/common \
$(pkg-config --cflags dbus-1) \
${SRC}/adhd/cras/src/.libs/libcrasserver.a \ ${SRC}/adhd/cras/src/.libs/libcrasserver.a \
-lcras_rust -lpthread -lrt -ludev -ldl -lm \ -lcras_rust -lpthread -lrt -ludev -ldl -lm -lsystemd \
$LIB_FUZZING_ENGINE \ $LIB_FUZZING_ENGINE \
-Wl,-Bstatic -liniparser -lasound -lspeexdsp -Wl,-Bdynamic -Wl,-Bstatic -liniparser -lasound -lspeexdsp -ldbus-1 -lsbc -Wl,-Bdynamic
done
zip -j ${OUT}/rclient_message_corpus.zip ${SRC}/adhd/cras/src/fuzz/corpus/* zip -j ${OUT}/rclient_message_corpus.zip ${SRC}/adhd/cras/src/fuzz/corpus/*
cp "${SRC}/adhd/cras/src/fuzz/cras_hfp_slc.dict" "${OUT}/cras_hfp_slc.dict"