From 44f9863192fc61d093b467fbf7d8306e8ee8d102 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sun, 14 Jan 2018 15:57:19 -0800 Subject: [PATCH] permute_tx: bail on empty permute_{inputs/outputs} arguments permute_outputs is sometimes called with empty arguments from initial_commit_tx. Make sure we guard against that case. We also do the same in permute_inputs for good measure. Signed-off-by: William Casarin --- common/permute_tx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/permute_tx.c b/common/permute_tx.c index f08decc05..3e09a34a6 100644 --- a/common/permute_tx.c +++ b/common/permute_tx.c @@ -59,6 +59,10 @@ void permute_inputs(struct bitcoin_tx_input *inputs, size_t num_inputs, { size_t i; + /* We can't permute nothing! */ + if (num_inputs == 0) + return; + /* Now do a dumb sort (num_inputs is small). */ for (i = 0; i < num_inputs-1; i++) { /* Swap best into first place. */ @@ -126,6 +130,10 @@ void permute_outputs(struct bitcoin_tx_output *outputs, size_t num_outputs, { size_t i; + /* We can't permute nothing! */ + if (num_outputs == 0) + return; + /* Now do a dumb sort (num_outputs is small). */ for (i = 0; i < num_outputs-1; i++) { /* Swap best into first place. */