Browse Source

libfuzz: add a NULL-termination in to_string

It's more useful if we actually want to use the output as, well, a
string..

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
ppa
Antoine Poinsot 4 years ago
committed by Christian Decker
parent
commit
506d524508
  1. 1
      tests/fuzz/Makefile
  2. 3
      tests/fuzz/libfuzz.c

1
tests/fuzz/Makefile

@ -46,6 +46,7 @@ FUZZ_COMMON_OBJS := \
wire/onion_wiregen.o \ wire/onion_wiregen.o \
wire/peer_wire.o \ wire/peer_wire.o \
wire/peer_wiregen.o \ wire/peer_wiregen.o \
wire/tlvstream.o \
wire/towire.o \ wire/towire.o \
wire/wire_io.o \ wire/wire_io.o \
wire/wire_sync.o wire/wire_sync.o

3
tests/fuzz/libfuzz.c

@ -34,10 +34,11 @@ const uint8_t **get_chunks(const void *ctx, const uint8_t *data,
char *to_string(const tal_t *ctx, const u8 *data, size_t data_size) char *to_string(const tal_t *ctx, const u8 *data, size_t data_size)
{ {
char *string = tal_arr(ctx, char, data_size); char *string = tal_arr(ctx, char, data_size + 1);
for (size_t i = 0; i < data_size; i++) for (size_t i = 0; i < data_size; i++)
string[i] = (char) data[i] % (CHAR_MAX + 1); string[i] = (char) data[i] % (CHAR_MAX + 1);
string[data_size] = '\0';
return string; return string;
} }

Loading…
Cancel
Save