summaryrefslogtreecommitdiff
path: root/ossfuzz
diff options
context:
space:
mode:
authorbimbashrestha <bshrestha.msae@gmail.com>2019-08-16 17:14:47 -0700
committerbimbashrestha <bshrestha.msae@gmail.com>2019-08-16 17:14:47 -0700
commitdc17d39c2fb962b591c73cf1467d89cf53b89156 (patch)
treed282c937e3a6e4511e24518f7bcaf47c248c63dd /ossfuzz
parentf839e9fe8a393117c64dff58196d36b741780ab0 (diff)
downloadlz4-dc17d39c2fb962b591c73cf1467d89cf53b89156.tar.gz
lz4-dc17d39c2fb962b591c73cf1467d89cf53b89156.tar.bz2
lz4-dc17d39c2fb962b591c73cf1467d89cf53b89156.zip
Adding comments, fixing nit, and hiding the struct in data producer api
Diffstat (limited to 'ossfuzz')
-rw-r--r--ossfuzz/compress_frame_fuzzer.c2
-rw-r--r--ossfuzz/compress_fuzzer.c2
-rw-r--r--ossfuzz/compress_hc_fuzzer.c2
-rw-r--r--ossfuzz/decompress_frame_fuzzer.c2
-rw-r--r--ossfuzz/decompress_fuzzer.c2
-rw-r--r--ossfuzz/fuzz_data_producer.c12
-rw-r--r--ossfuzz/fuzz_data_producer.h12
-rw-r--r--ossfuzz/round_trip_hc_fuzzer.c2
8 files changed, 25 insertions, 11 deletions
diff --git a/ossfuzz/compress_frame_fuzzer.c b/ossfuzz/compress_frame_fuzzer.c
index 344917a..75c609f 100644
--- a/ossfuzz/compress_frame_fuzzer.c
+++ b/ossfuzz/compress_frame_fuzzer.c
@@ -10,14 +10,12 @@
#include <string.h>
#include "fuzz_helpers.h"
-#include "fuzz_data_producer.h"
#include "lz4.h"
#include "lz4frame.h"
#include "lz4_helpers.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
- FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
uint32_t seed = FUZZ_seed(&data, &size);
LZ4F_preferences_t const prefs = FUZZ_randomPreferences(&seed);
size_t const compressBound = LZ4F_compressFrameBound(size, &prefs);
diff --git a/ossfuzz/compress_fuzzer.c b/ossfuzz/compress_fuzzer.c
index 42efbd3..9d72e72 100644
--- a/ossfuzz/compress_fuzzer.c
+++ b/ossfuzz/compress_fuzzer.c
@@ -22,7 +22,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
char* const rt = (char*)malloc(size);
/* Restrict to remaining data from producer */
- size = producer->size;
+ size = FUZZ_dataProducer_remainingBytes(producer);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(rt);
diff --git a/ossfuzz/compress_hc_fuzzer.c b/ossfuzz/compress_hc_fuzzer.c
index f06f6dd..5f22104 100644
--- a/ossfuzz/compress_hc_fuzzer.c
+++ b/ossfuzz/compress_hc_fuzzer.c
@@ -25,7 +25,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
producer, LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX);
/* Restrict to remaining data from producer */
- size = producer->size;
+ size = FUZZ_dataProducer_remainingBytes(producer);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(rt);
diff --git a/ossfuzz/decompress_frame_fuzzer.c b/ossfuzz/decompress_frame_fuzzer.c
index 4c8ac39..60d2ea1 100644
--- a/ossfuzz/decompress_frame_fuzzer.c
+++ b/ossfuzz/decompress_frame_fuzzer.c
@@ -43,7 +43,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION);
/* Restrict to remaining data from producer */
- size = producer->size;
+ size = FUZZ_dataProducer_remainingBytes(producer);
FUZZ_ASSERT(dctx);
FUZZ_ASSERT(dst);
diff --git a/ossfuzz/decompress_fuzzer.c b/ossfuzz/decompress_fuzzer.c
index ae03ba9..bc4190b 100644
--- a/ossfuzz/decompress_fuzzer.c
+++ b/ossfuzz/decompress_fuzzer.c
@@ -27,7 +27,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
char* const smallDict = dataAfterDict - smallDictSize;
/* Restrict to remaining data from producer */
- size = producer->size;
+ size = FUZZ_dataProducer_remainingBytes(producer);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(dict);
diff --git a/ossfuzz/fuzz_data_producer.c b/ossfuzz/fuzz_data_producer.c
index ae07575..992f5a7 100644
--- a/ossfuzz/fuzz_data_producer.c
+++ b/ossfuzz/fuzz_data_producer.c
@@ -1,7 +1,15 @@
#include "fuzz_data_producer.h"
+struct FUZZ_dataProducer_s{
+ const uint8_t *data;
+ size_t size;
+};
+
FUZZ_dataProducer_t *FUZZ_dataProducer_create(const uint8_t *data, size_t size) {
FUZZ_dataProducer_t *producer = malloc(sizeof(FUZZ_dataProducer_t));
+
+ FUZZ_ASSERT(producer != NULL);
+
producer->data = data;
producer->size = size;
return producer;
@@ -30,3 +38,7 @@ uint32_t FUZZ_dataProducer_uint32(FUZZ_dataProducer_t *producer, uint32_t min,
return min + result % (range + 1);
}
+
+size_t FUZZ_dataProducer_remainingBytes(FUZZ_dataProducer_t *producer){
+ return producer->size;
+}
diff --git a/ossfuzz/fuzz_data_producer.h b/ossfuzz/fuzz_data_producer.h
index 389ec2a..8df5257 100644
--- a/ossfuzz/fuzz_data_producer.h
+++ b/ossfuzz/fuzz_data_producer.h
@@ -5,14 +5,18 @@
#include "fuzz_helpers.h"
-typedef struct {
- const uint8_t *data;
- size_t size;
-} FUZZ_dataProducer_t;
+/* Struct used for maintaining the state of the data */
+typedef struct FUZZ_dataProducer_s FUZZ_dataProducer_t;
+/* Returns a data producer state struct. Use for producer initialization. */
FUZZ_dataProducer_t *FUZZ_dataProducer_create(const uint8_t *data, size_t size);
+/* Frees the data producer */
void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer);
+/* Returns value between [min, max] */
uint32_t FUZZ_dataProducer_uint32(FUZZ_dataProducer_t *producer, uint32_t min,
uint32_t max);
+
+/* Returns the size of the remaining bytes of data in the producer */
+size_t FUZZ_dataProducer_remainingBytes(FUZZ_dataProducer_t *producer);
diff --git a/ossfuzz/round_trip_hc_fuzzer.c b/ossfuzz/round_trip_hc_fuzzer.c
index 22b5e8f..8406809 100644
--- a/ossfuzz/round_trip_hc_fuzzer.c
+++ b/ossfuzz/round_trip_hc_fuzzer.c
@@ -23,7 +23,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
producer, LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX);
/* Restrict to remaining data from producer */
- size = producer->size;
+ size = FUZZ_dataProducer_remainingBytes(producer);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(rt);