diff options
author | Max Dymond <cmeister2@gmail.com> | 2019-06-28 19:54:46 (GMT) |
---|---|---|
committer | Max Dymond <cmeister2@gmail.com> | 2019-06-28 19:54:46 (GMT) |
commit | 88a7cfd7283ea9c51fd044b9f58aee47b9ed3d16 (patch) | |
tree | 36d13de76bb9d07cbe8877cdff59cc3896d3af20 | |
parent | a5cf079d4dc9097c4e58f0eb7b0996b0a6d91696 (diff) | |
download | lz4-88a7cfd7283ea9c51fd044b9f58aee47b9ed3d16.zip lz4-88a7cfd7283ea9c51fd044b9f58aee47b9ed3d16.tar.gz lz4-88a7cfd7283ea9c51fd044b9f58aee47b9ed3d16.tar.bz2 |
Code review markups:
- Correct use of CPPFLAGS
- Detect allocation failure
- Add a CHECK macro for failure
-rw-r--r-- | ossfuzz/Makefile | 12 | ||||
-rw-r--r-- | ossfuzz/compress_fuzzer.cc | 18 | ||||
-rwxr-xr-x | ossfuzz/ossfuzz.sh | 5 |
3 files changed, 18 insertions, 17 deletions
diff --git a/ossfuzz/Makefile b/ossfuzz/Makefile index 94829b2..2a7e439 100644 --- a/ossfuzz/Makefile +++ b/ossfuzz/Makefile @@ -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) diff --git a/ossfuzz/compress_fuzzer.cc b/ossfuzz/compress_fuzzer.cc index 006a0ab..4a720e2 100644 --- a/ossfuzz/compress_fuzzer.cc +++ b/ossfuzz/compress_fuzzer.cc @@ -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; } diff --git a/ossfuzz/ossfuzz.sh b/ossfuzz/ossfuzz.sh index e0cb63c..87bc213 100755 --- a/ossfuzz/ossfuzz.sh +++ b/ossfuzz/ossfuzz.sh @@ -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)" |