diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2024-06-17 13:45:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 13:45:47 +0200 |
commit | 26cc1f131f2576a49a3b9c43cd4b787b067b3f5a (patch) | |
tree | 90fc819791daee5fafb3372fa0e2f9b75b4368b5 /fuzz/fuzz_alg_shoco.cpp | |
parent | a35fae6b75924394ddbf7df4fc5a6eb114cf76d6 (diff) |
fuzz: improve fuzzing coverage (#2474)
Remove some code never triggered
AFP: the removed check is included in the following one
MQTT: fix flags extraction
Diffstat (limited to 'fuzz/fuzz_alg_shoco.cpp')
-rw-r--r-- | fuzz/fuzz_alg_shoco.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/fuzz/fuzz_alg_shoco.cpp b/fuzz/fuzz_alg_shoco.cpp index 40fe0f0f4..68d262660 100644 --- a/fuzz/fuzz_alg_shoco.cpp +++ b/fuzz/fuzz_alg_shoco.cpp @@ -1,5 +1,6 @@ #include <stdint.h> #include "shoco.h" +#include "ndpi_api.h" #include "fuzzer/FuzzedDataProvider.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { @@ -7,16 +8,25 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const char *in; size_t in_len, out_len; char out[8192], orig[8192]; + int higher_level_api; /* No memory allocations involved */ + higher_level_api = fuzzed_data.ConsumeBool(); + std::string s = fuzzed_data.ConsumeRemainingBytesAsString().c_str(); in = s.c_str(); in_len = strlen(in); - out_len = shoco_compress(in, in_len, out, sizeof(out)); - if(out_len <= sizeof(out)) /* No error */ - shoco_decompress(out, out_len, orig, sizeof(orig)); + if(!higher_level_api) { + out_len = shoco_compress(in, in_len, out, sizeof(out)); + if(out_len <= sizeof(out)) /* No error */ + shoco_decompress(out, out_len, orig, sizeof(orig)); + } else { + out_len = ndpi_compress_str(in, in_len, out, sizeof(out)); + if(out_len != 0) /* No error */ + ndpi_decompress_str(out, out_len, orig, sizeof(orig)); + } return 0; } |