invoice: Check duplicate preimage when explicitly sprcified.

Reported-by: @mcudev
This commit is contained in:
ZmnSCPxj
2018-04-24 23:04:33 +00:00
committed by Rusty Russell
parent 89ff46f1e6
commit 079778e357
7 changed files with 77 additions and 0 deletions

View File

@@ -297,6 +297,16 @@ static void json_invoice(struct command *cmd,
/* Generate preimage hash. */
sha256(&rhash, r.r, sizeof(r.r));
/* Check duplicate preimage if explicitly specified.
* We do not check when it is randomly generated, since
* the probability of that matching is very low.
*/
if (preimagetok &&
wallet_invoice_find_by_rhash(cmd->ld->wallet, &invoice, &rhash)) {
command_fail(cmd, "preimage already used");
return;
}
/* Construct bolt11 string. */
b11 = new_bolt11(cmd, msatoshi_val);
b11->chain = get_chainparams(cmd->ld);