offers: save replytok properly.

We carefully copied the buffer, but the tok is inside an array.  We get away
with it for now, but with coming changes it gets freed.  We need to copy
the token and all the tokens within it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-10-01 06:49:37 +09:30 committed by Christian Decker
parent a71f2475d5
commit af7e0a1183
2 changed files with 4 additions and 2 deletions

View file

@ -327,7 +327,8 @@ struct command_result *handle_invoice(struct command *cmd,
/* Make a copy of entire buffer, for later. */
inv->buf = tal_dup_arr(inv, char, buf, replytok->end, 0);
inv->replytok = replytok;
inv->replytok = tal_dup_arr(inv, jsmntok_t, replytok,
json_next(replytok) - replytok, 0);
inv->inv = tlv_invoice_new(cmd);
if (!fromwire_invoice(&invbin, &len, inv->inv)) {

View file

@ -838,7 +838,8 @@ struct command_result *handle_invoice_request(struct command *cmd,
/* Make a copy of entire buffer, for later. */
ir->buf = tal_dup_arr(ir, char, buf, replytok->end, 0);
ir->replytok = replytok;
ir->replytok = tal_dup_arr(ir, jsmntok_t, replytok,
json_next(replytok) - replytok, 0);
ir->invreq = tlv_invoice_request_new(cmd);
if (!fromwire_invoice_request(&invreqbin, &len, ir->invreq)) {