From c40e9ad51b1fc0129f116466a31663112a0a5f4c Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Mon, 24 Aug 2020 10:28:20 +1200 Subject: [PATCH] psbt: Allow doubly-present but matching fields when combining exclusive fields --- src/psbt.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/psbt.c b/src/psbt.c index 3e015c981..9b0421994 100644 --- a/src/psbt.c +++ b/src/psbt.c @@ -2005,12 +2005,17 @@ int wally_psbt_to_base64(const struct wally_psbt *psbt, uint32_t flags, char **o return ret; } -#define COMBINE_BYTES(typ, member, ALLOW_DUPS) do { \ - if (!dst->member && src->member) { \ - if (!ALLOW_DUPS) return WALLY_EINVAL; \ - ret = wally_psbt_ ## typ ## _set_ ## member(dst, src->member, src->member ## _len); \ - if (ret != WALLY_OK) \ - return ret; \ +#define COMBINE_BYTES(TYP, MEMBER, ALLOW_DUPS) do { \ + if (src->MEMBER) { \ + if (dst->MEMBER && !ALLOW_DUPS) { \ + if (dst->MEMBER ## _len != src->MEMBER ## _len || \ + memcmp(dst->MEMBER, src->MEMBER, dst->MEMBER ## _len) != 0) \ + return WALLY_EINVAL; \ + } else if (!dst->MEMBER) { \ + ret = wally_psbt_ ## TYP ## _set_ ## MEMBER(dst, src->MEMBER, src->MEMBER ## _len); \ + if (ret != WALLY_OK) \ + return ret; \ + } \ } } while (0) static int combine_txs(struct wally_tx **dst, struct wally_tx *src)