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
This commit is contained in:
Christian Decker 2020-12-04 11:52:15 +01:00 committed by Rusty Russell
parent 47b8b46d54
commit e186b2620a

View File

@ -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;