wire: add fromwire_tal_arrn() helper.

Does the allocation and copying; this is useful because we can
avoid being fooled into doing giant allocations.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-03-04 14:43:00 +10:30
committed by Christian Decker
parent 524d22e4cc
commit c92e782e22
5 changed files with 27 additions and 15 deletions

View File

@@ -12,8 +12,8 @@ struct onionreply *fromwire_onionreply(const tal_t *ctx,
const u8 **cursor, size_t *max)
{
struct onionreply *r = tal(ctx, struct onionreply);
r->contents = tal_arr(r, u8, fromwire_u16(cursor, max));
fromwire_u8_array(cursor, max, r->contents, tal_count(r->contents));
r->contents = fromwire_tal_arrn(r, cursor, max,
fromwire_u16(cursor, max));
if (!*cursor)
return tal_free(r);
return r;