diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2024-11-01 18:17:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-01 18:17:22 +0100 |
commit | b63f74a0806ed9d6b80e81e0232ce94a095f1951 (patch) | |
tree | 3321ff59ba91f294100595a794e145d7fb06a463 /fuzz/fuzz_alg_quick_encryption.cpp | |
parent | 137d87fd873197f0fe43f627a90203e1696fdb2c (diff) |
fuzz: improve coverage (#2612)
Add fuzzer to test `ndpi_quick_encrypt()` and `ndpi_quick_decrypt()`
Diffstat (limited to 'fuzz/fuzz_alg_quick_encryption.cpp')
-rw-r--r-- | fuzz/fuzz_alg_quick_encryption.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/fuzz/fuzz_alg_quick_encryption.cpp b/fuzz/fuzz_alg_quick_encryption.cpp new file mode 100644 index 000000000..6bf65bdd7 --- /dev/null +++ b/fuzz/fuzz_alg_quick_encryption.cpp @@ -0,0 +1,30 @@ +#include "ndpi_api.h" +#include "fuzz_common_code.h" + +#include <stdlib.h> +#include <stdint.h> +#include "fuzzer/FuzzedDataProvider.h" + + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + FuzzedDataProvider fuzzed_data(data, size); + char *enc_buffer, *dec_buffer; + u_int16_t encrypted_msg_len, decrypted_msg_len; + + if(fuzzed_data.remaining_bytes() <= 64) /* Some data */ + return -1; + + /* To allow memory allocation failures */ + fuzz_set_alloc_callbacks_and_seed(size); + + std::vector<unsigned char>key = fuzzed_data.ConsumeBytes<u_int8_t>(64); + std::vector<char>cleartext_msg = fuzzed_data.ConsumeRemainingBytes<char>(); + + enc_buffer = ndpi_quick_encrypt(cleartext_msg.data(), cleartext_msg.size(), &encrypted_msg_len, key.data()); + if(enc_buffer) { + dec_buffer = ndpi_quick_decrypt(enc_buffer, encrypted_msg_len, &decrypted_msg_len, key.data()); + ndpi_free(enc_buffer); + ndpi_free(dec_buffer); + } + return 0; +} |