From 6d00a9e0bd4cdb2be26577f53b75b3078cefd4c3 Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Fri, 27 Jan 2023 07:09:18 +0100 Subject: fuzz: add a new fuzzer to test serialization/deserialization code (#1876) Autodetecting the needed buffer size is quite complex (especially with float/double values) so it is mandatory to properly check for `ndpi_snprintf` truncation. These issues have been undetected so far probably because the default buffer is big enough for all common cases. Add an example of usage of `ndpi_deserialize_clone_all()` (taken from `ntopng`) --- src/include/ndpi_api.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/include') diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index d9e48047f..9968e9eb3 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -1248,6 +1248,16 @@ extern "C" { */ int ndpi_serialize_uint32_float(ndpi_serializer *serializer, u_int32_t key, float value, const char *format /* e.f. "%.2f" */); + /** + * Serialize a 32-bit unsigned int key and a double value + * @param serializer The serializer handle + * @param key The field name or ID + * @param value The field value + * @param format The float value format + * @return 0 on success, a negative number otherwise + */ + int ndpi_serialize_uint32_double(ndpi_serializer *serializer, u_int32_t key, double value, const char *format /* e.f. "%.2f" */); + /** * Serialize a 32-bit unsigned int key and a double value * @param serializer The serializer handle @@ -1276,6 +1286,16 @@ extern "C" { */ int ndpi_serialize_uint32_boolean(ndpi_serializer *serializer, u_int32_t key, u_int8_t value); + /** + * Serialize a 32-bit unsigned int and an unterminated string value + * @param serializer The serializer handle + * @param key The field name or ID + * @param value The field value + * @param vlen The value length + * @return 0 on success, a negative number otherwise + */ + int ndpi_serialize_uint32_binary(ndpi_serializer *serializer, u_int32_t key, const char *_value, u_int16_t vlen); + /** * Serialize an unterminated string key and a 32-bit signed int value * @param serializer The serializer handle -- cgit v1.2.3