mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 09:34:24 +01:00
fuzz: add a 'to_string' function to libfuzz
We want to use it outside of fuzz-amount Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
committed by
neil saitug
parent
419612c4bd
commit
bf0a2f2b85
@@ -21,10 +21,7 @@ void run(const uint8_t *data, size_t size)
|
||||
|
||||
/* We should not crash when parsing any string. */
|
||||
|
||||
string = tal_arr(NULL, char, size);
|
||||
for (size_t i = 0; i < size; i++)
|
||||
string[i] = (char) data[i] % (CHAR_MAX + 1);
|
||||
|
||||
string = to_string(NULL, data, size);
|
||||
parse_amount_msat(&msat, string, tal_count(string));
|
||||
parse_amount_sat(&sat, string, tal_count(string));
|
||||
tal_free(string);
|
||||
|
||||
@@ -31,3 +31,13 @@ const uint8_t **get_chunks(const void *ctx, const uint8_t *data,
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
char *to_string(const tal_t *ctx, const u8 *data, size_t data_size)
|
||||
{
|
||||
char *string = tal_arr(ctx, char, data_size);
|
||||
|
||||
for (size_t i = 0; i < data_size; i++)
|
||||
string[i] = (char) data[i] % (CHAR_MAX + 1);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef LIGHTNING_TESTS_FUZZ_LIBFUZZ_H
|
||||
#define LIGHTNING_TESTS_FUZZ_LIBFUZZ_H
|
||||
|
||||
#include <ccan/ccan/short_types/short_types.h>
|
||||
#include <ccan/ccan/tal/tal.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -15,4 +17,7 @@ void run(const uint8_t *data, size_t size);
|
||||
const uint8_t **get_chunks(const void *ctx, const uint8_t *data,
|
||||
size_t data_size, size_t chunk_size);
|
||||
|
||||
/* Copy the data as a string. */
|
||||
char *to_string(const tal_t *ctx, const u8 *data, size_t data_size);
|
||||
|
||||
#endif /* LIGHTNING_TESTS_FUZZ_LIBFUZZ_H */
|
||||
|
||||
Reference in New Issue
Block a user