Skip to content

Commit bc0a4d3

Browse files
author
Chandra Pratap
committed
fuzz-tests: Add a roundtrip check for bigsize_put()
Add a roundtrip check for `bigsize_put()` using `bigsize_get()`. This enforces a stricter check for the former and adds a test for the latter, which is currently untested.
1 parent 466c048 commit bc0a4d3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tests/fuzz/fuzz-bigsize.c

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

17-
for (size_t max = 1; max <= BIGSIZE_MAX_LEN; max++) {
18-
wire_chunks = get_chunks(NULL, data, size, max);
17+
for (size_t chunk_size = 1; chunk_size <= BIGSIZE_MAX_LEN; chunk_size++) {
18+
wire_chunks = get_chunks(NULL, data, size, chunk_size);
1919
for (size_t i = 0; i < tal_count(wire_chunks); i++) {
2020
wire_max = tal_count(wire_chunks[i]);
2121
wire_ptr = wire_chunks[i];
2222

23-
bigsize_t bs = fromwire_bigsize(&wire_ptr, &wire_max);
23+
bigsize_t bs = fromwire_bigsize(&wire_ptr, &wire_max), bs_decoded;
2424
assert(bigsize_put(buff, bs) > 0);
2525
assert(bigsize_len(bs));
26+
assert(bigsize_get(buff, sizeof(buff), &bs_decoded) == bigsize_len(bs));
27+
assert(bs_decoded == bs);
2628

2729
wire_buff = tal_arr(NULL, uint8_t, 8);
2830
towire_bigsize(&wire_buff, bs);

0 commit comments

Comments
 (0)