OSS-Fuzz: Build fuzz targets using C++ compiler

Otherwise, the targets will require libstdc++, the i386 version of which
is not available in the OSS-Fuzz runtime environment.  The OSS-Fuzz
build environment passes -stdlib:libc++ in the CXXFLAGS environment
variable in order to mitigate this issue, since the runtime environment
has the i386 version of libc++, but using that compiler flag requires
using the C++ compiler.
This commit is contained in:
DRC
2021-04-02 14:50:35 -05:00
parent 7b57cba6b4
commit 6ad658be17
5 changed files with 14 additions and 7 deletions

View File

@@ -16,6 +16,12 @@ if(NOT FUZZ_LIBRARY)
endif()
message(STATUS "FUZZ_LIBRARY = ${FUZZ_LIBRARY}")
enable_language(CXX)
set(EFFECTIVE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
message(STATUS "C++ Compiler flags = ${EFFECTIVE_CXX_FLAGS}")
macro(add_fuzz_target target source_file)
add_executable(${target}_fuzzer ${source_file})
if(NOT ENABLE_SHARED)
@@ -29,8 +35,8 @@ endmacro()
# NOTE: This target is named libjpeg_turbo_fuzzer instead of decompress_fuzzer
# in order to preserve the corpora from Google's OSS-Fuzz target for
# libjpeg-turbo, which this target replaces.
add_fuzz_target(libjpeg_turbo decompress.c)
add_fuzz_target(libjpeg_turbo decompress.cc)
add_fuzz_target(decompress_yuv decompress_yuv.c)
add_fuzz_target(decompress_yuv decompress_yuv.cc)
add_fuzz_target(transform transform.c)
add_fuzz_target(transform transform.cc)

View File

@@ -4,7 +4,8 @@ set -u
set -e
cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_STATIC=1 -DENABLE_SHARED=0 \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-g -DNDEBUG" -DCMAKE_INSTALL_PREFIX=$WORK \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-g -DNDEBUG" \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-g -DNDEBUG" -DCMAKE_INSTALL_PREFIX=$WORK \
-DWITH_FUZZ=1 -DFUZZ_BINDIR=$OUT -DFUZZ_LIBRARY=$LIB_FUZZING_ENGINE
make "-j$(nproc)" "--load-average=$(nproc)"
make install

View File

@@ -34,7 +34,7 @@
#define NUMPF 4
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
tjhandle handle = NULL;
unsigned char *dstBuf = NULL;

View File

@@ -34,7 +34,7 @@
#define NUMPF 3
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
tjhandle handle = NULL;
unsigned char *dstBuf = NULL, *yuvBuf = NULL;

View File

@@ -35,7 +35,7 @@
#define NUMXFORMS 3
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
tjhandle handle = NULL;
unsigned char *dstBufs[NUMXFORMS] = { NULL, NULL, NULL };