From e186b2620af7a8cb49f98293bb6c7d61cdf4ea8a Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 4 Dec 2020 11:52:15 +0100 Subject: [PATCH] txprepare: Verify that outputs arg is an array We were not checking that outputs is indeed an array, and just going ahead creating the array of outputs. Since `tok->size` for a string is 0 we ended up ignoring the argument altogether and thus the created transaction would end up only with a single change output. Fixes #4258 --- plugins/txprepare.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/txprepare.c b/plugins/txprepare.c index eba0bbd08..ed22552bb 100644 --- a/plugins/txprepare.c +++ b/plugins/txprepare.c @@ -67,6 +67,13 @@ static struct command_result *param_outputs(struct command *cmd, size_t i; const jsmntok_t *t; + if (tok->type != JSMN_ARRAY) { + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "Expected an array of outputs in the " + "format '[{\"txid\":0}, ...]', got \"%s\"", + json_strdup(tmpctx, buffer, tok)); + } + txp->outputs = tal_arr(txp, struct tx_output, tok->size); txp->output_total = AMOUNT_SAT(0); txp->all_output_idx = -1;