mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 00:24:19 +01:00
psbt: try one big alloc and fail instead of incremental buffer increases
was running into buffer overrun errors? something about the iteration method was broken
This commit is contained in:
committed by
Christian Decker
parent
6197bd2b82
commit
cc6eba1d72
@@ -141,19 +141,17 @@ void psbt_rm_output(struct wally_psbt *psbt,
|
|||||||
void towire_psbt(u8 **pptr, const struct wally_psbt *psbt)
|
void towire_psbt(u8 **pptr, const struct wally_psbt *psbt)
|
||||||
{
|
{
|
||||||
/* Let's include the PSBT bytes */
|
/* Let's include the PSBT bytes */
|
||||||
for (size_t room = 1024; room < 1024 * 1000; room *= 2) {
|
size_t room = 1024 * 1000;
|
||||||
u8 *pbt_bytes = tal_arr(NULL, u8, room);
|
u8 *pbt_bytes = tal_arr(NULL, u8, room);
|
||||||
size_t bytes_written;
|
size_t bytes_written;
|
||||||
if (wally_psbt_to_bytes(psbt, pbt_bytes, room, &bytes_written) == WALLY_OK) {
|
if (wally_psbt_to_bytes(psbt, pbt_bytes, room, &bytes_written) != WALLY_OK) {
|
||||||
towire_u32(pptr, bytes_written);
|
/* something went wrong. bad libwally ?? */
|
||||||
towire_u8_array(pptr, pbt_bytes, bytes_written);
|
abort();
|
||||||
tal_free(pbt_bytes);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tal_free(pbt_bytes);
|
|
||||||
}
|
}
|
||||||
/* PSBT is too big */
|
|
||||||
abort();
|
towire_u32(pptr, bytes_written);
|
||||||
|
towire_u8_array(pptr, pbt_bytes, bytes_written);
|
||||||
|
tal_free(pbt_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wally_psbt *fromwire_psbt(const tal_t *ctx,
|
struct wally_psbt *fromwire_psbt(const tal_t *ctx,
|
||||||
|
|||||||
Reference in New Issue
Block a user