Skip to content

Commit 466c048

Browse files
author
Chandra Pratap
committed
fuzz-tests: Replace hardcoded chunk size with iteration over sizes
Changelog-None: The exisiting fuzz test only extracts chunks of a fixed size (8) from the fuzzer's input. Replace this with an iteration over a set of chunk sizes (1 to BIGSIZE_MAX_LEN) for better coverage. While at it, get rid of the check `if (bs != 0)` because 0 is a valid value for bigsize_t as well.
1 parent 44972b2 commit 466c048

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/fuzz/fuzz-bigsize.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@ void run(const uint8_t *data, size_t size)
1414
const uint8_t **wire_chunks, *wire_ptr;
1515
size_t wire_max;
1616

17-
wire_chunks = get_chunks(NULL, data, size, 8);
18-
for (size_t i = 0; i < tal_count(wire_chunks); i++) {
19-
wire_max = tal_count(wire_chunks[i]);
20-
wire_ptr = wire_chunks[i];
17+
for (size_t max = 1; max <= BIGSIZE_MAX_LEN; max++) {
18+
wire_chunks = get_chunks(NULL, data, size, max);
19+
for (size_t i = 0; i < tal_count(wire_chunks); i++) {
20+
wire_max = tal_count(wire_chunks[i]);
21+
wire_ptr = wire_chunks[i];
2122

22-
bigsize_t bs = fromwire_bigsize(&wire_ptr, &wire_max);
23-
if (bs != 0) {
24-
/* We have a valid bigsize type, now we should not error. */
23+
bigsize_t bs = fromwire_bigsize(&wire_ptr, &wire_max);
2524
assert(bigsize_put(buff, bs) > 0);
2625
assert(bigsize_len(bs));
2726

2827
wire_buff = tal_arr(NULL, uint8_t, 8);
2928
towire_bigsize(&wire_buff, bs);
3029
tal_free(wire_buff);
3130
}
31+
tal_free(wire_chunks);
3232
}
33-
tal_free(wire_chunks);
3433
}

0 commit comments

Comments
 (0)