More markups for style changes

This commit is contained in:
Max Dymond 2019-06-29 00:23:06 +01:00
parent 02b5b3c242
commit e2a33f12e1
No known key found for this signature in database
GPG Key ID: 12A8D9E2219BD5FA
4 changed files with 39 additions and 28 deletions

View File

@ -31,28 +31,28 @@ LIB_FUZZING_ENGINE ?= standaloneengine.o
DEBUGLEVEL?= 1 DEBUGLEVEL?= 1
DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL) DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL)
CFLAGS += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS) LZ4_CFLAGS = $(CFLAGS) $(DEBUGFLAGS) $(MOREFLAGS)
CXXFLAGS += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS) LZ4_CXXFLAGS = $(CXXFLAGS) $(DEBUGFLAGS) $(MOREFLAGS)
CPPFLAGS += -DXXH_NAMESPACE=LZ4_ LZ4_CPPFLAGS = $(CPPFLAGS) -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_
include ../Makefile.inc include ../Makefile.inc
# Include a rule to build the static library if calling this target # Include a rule to build the static library if calling this target
# directly. # directly.
$(LZ4DIR)/liblz4.a: $(LZ4DIR)/liblz4.a:
$(MAKE) -C $(LZ4DIR) CFLAGS="$(CFLAGS)" liblz4.a $(MAKE) -C $(LZ4DIR) CFLAGS="$(LZ4_CFLAGS)" liblz4.a
%.o: %.c %.o: %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) $< -o $@
# Generic rule for generating fuzzers # Generic rule for generating fuzzers
%_fuzzer: %_fuzzer.o $(LZ4DIR)/liblz4.a %_fuzzer: %_fuzzer.o $(LZ4DIR)/liblz4.a
# Compile the standalone code just in case. The OSS-Fuzz code might # Compile the standalone code just in case. The OSS-Fuzz code might
# override the LIB_FUZZING_ENGINE value to "-fsanitize=fuzzer" # override the LIB_FUZZING_ENGINE value to "-fsanitize=fuzzer"
$(CC) -c $(CFLAGS) $(CPPFLAGS) standaloneengine.c -o standaloneengine.o $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) standaloneengine.c -o standaloneengine.o
# Now compile the actual fuzzer. # Now compile the actual fuzzer.
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT) $(CXX) $(LZ4_CXXFLAGS) $(LZ4_CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
%_fuzzer_clean: %_fuzzer_clean:
$(RM) $*_fuzzer $*_fuzzer.o standaloneengine.o $(RM) $*_fuzzer $*_fuzzer.o standaloneengine.o

View File

@ -10,8 +10,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size_t const compressed_dest_size = LZ4_compressBound(size); size_t const compressed_dest_size = LZ4_compressBound(size);
char *const dest_buffer = (char *)malloc(compressed_dest_size); char *const dest_buffer = (char *)malloc(compressed_dest_size);
if (dest_buffer != NULL) CHECK(dest_buffer != NULL);
{
// Allocation succeeded, try compressing the incoming data. // Allocation succeeded, try compressing the incoming data.
int result = LZ4_compress_default((const char*)data, int result = LZ4_compress_default((const char*)data,
dest_buffer, dest_buffer,
@ -20,7 +20,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
CHECK(result != 0); CHECK(result != 0);
free(dest_buffer); free(dest_buffer);
}
return 0; return 0;
} }

View File

@ -7,11 +7,12 @@
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{ {
// TODO: Size input buffer pseudo-randomly based on seed extracted from input
size_t const buffer_size = 10 * 1024 * 1024; size_t const buffer_size = 10 * 1024 * 1024;
char *const dest_buffer = (char *)malloc(buffer_size); char *const dest_buffer = (char *)malloc(buffer_size);
if (dest_buffer != NULL) CHECK(dest_buffer != NULL);
{
// Allocation succeeded, try decompressing the incoming data. // Allocation succeeded, try decompressing the incoming data.
int result = LZ4_decompress_safe((const char*)data, int result = LZ4_decompress_safe((const char*)data,
dest_buffer, dest_buffer,
@ -22,7 +23,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
(void)result; (void)result;
free(dest_buffer); free(dest_buffer);
}
return 0; return 0;
} }

View File

@ -1,3 +1,15 @@
#ifndef TESTINPUT_H_INCLUDED
#define TESTINPUT_H_INCLUDED
#include <inttypes.h> #include <inttypes.h>
#if defined (__cplusplus)
extern "C" {
#endif
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
#if defined(__cplusplus)
}
#endif
#endif