Code review markups:

- Correct use of CPPFLAGS
- Detect allocation failure
- Add a CHECK macro for failure
This commit is contained in:
Max Dymond 2019-06-28 20:54:46 +01:00
parent a5cf079d4d
commit 88a7cfd728
No known key found for this signature in database
GPG Key ID: 12A8D9E2219BD5FA
3 changed files with 18 additions and 17 deletions

View File

@ -30,9 +30,9 @@ LIB_FUZZING_ENGINE ?= standaloneengine.o
DEBUGLEVEL?= 1
DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL)
CFLAGS += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS)
CPPFLAGS+= -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_
FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
CFLAGS += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS)
CXXFLAGS += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS)
CPPFLAGS += -DXXH_NAMESPACE=LZ4_
include ../Makefile.inc
@ -42,13 +42,13 @@ $(LZ4DIR)/liblz4.a:
$(MAKE) -C $(LZ4DIR) CFLAGS="$(CFLAGS)" liblz4.a
%.o: %.cc
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
.PHONY: compress_fuzzer
compress_fuzzer: compress_fuzzer.o $(LZ4DIR)/liblz4.a
# Compile the standalone code just in case. The OSS-Fuzz code might
# override the LIB_FUZZING_ENGINE value to "-fsanitize=fuzzer"
$(CXX) -c $(CFLAGS) $(CPPFLAGS) standaloneengine.cc -o standaloneengine.o
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) standaloneengine.cc -o standaloneengine.o
# Now compile the actual fuzzer.
$(CXX) $(FLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)

View File

@ -3,20 +3,24 @@
#include <stdlib.h>
#include "lz4.h"
#define CHECK(COND) if (!(COND)) { abort(); }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
size_t const compressed_dest_size = LZ4_compressBound(size);
char *const dest_buffer = (char *)malloc(compressed_dest_size);
int result = LZ4_compress_default((const char*)data, dest_buffer,
size, compressed_dest_size);
if (result == 0)
if (dest_buffer != NULL)
{
abort();
}
// Allocation succeeded, try compressing the incoming data.
int result = LZ4_compress_default((const char*)data,
dest_buffer,
size,
compressed_dest_size);
CHECK(result != 0);
free(dest_buffer);
free(dest_buffer);
}
return 0;
}

View File

@ -6,14 +6,11 @@
# Save off the current folder as the build root.
export BUILD_ROOT=$PWD
# lz4 uses CPPFLAGS rather than CXX flags.
export CPPFLAGS="${CXXFLAGS}"
echo "CC: $CC"
echo "CXX: $CXX"
echo "LIB_FUZZING_ENGINE: $LIB_FUZZING_ENGINE"
echo "CFLAGS: $CFLAGS"
echo "CPPFLAGS: $CPPFLAGS"
echo "CXXFLAGS: $CXXFLAGS"
echo "OUT: $OUT"
export MAKEFLAGS+="-j$(nproc)"