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 /ossfuzz/compress_fuzzer.cc | |
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
Diffstat (limited to 'ossfuzz/compress_fuzzer.cc')
-rw-r--r-- | ossfuzz/compress_fuzzer.cc | 18 |
1 files changed, 11 insertions, 7 deletions
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; } |