Skip to content

Commit

Permalink
pay: Use safe list traversal when completing suspended payments
Browse files Browse the repository at this point in the history
When traversing the list we call `command_finished` which modifies the
list we are traversing. This ensures we don't end up advancing in the
list iteration.

Reported-by: Rusty Russell <@rustyrussell>
  • Loading branch information
cdecker authored and niftynei committed Aug 8, 2022
1 parent 65a449e commit da0b651
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ static const char *init(struct plugin *p,

static void on_payment_success(struct payment *payment)
{
struct payment *p;
struct payment *p, *nxt;
struct payment_tree_result result = payment_collect_result(payment);
struct json_stream *ret;
struct command *cmd;
Expand All @@ -585,7 +585,7 @@ static void on_payment_success(struct payment *payment)
/* Iterate through any pending payments we suspended and
* terminate them. */

list_for_each(&payments, p, list) {
list_for_each_safe(&payments, p, nxt, list) {
/* The result for the active payment is returned in
* `payment_finished`. */
if (payment == p)
Expand Down Expand Up @@ -672,9 +672,9 @@ static void payment_json_add_attempts(struct json_stream *s,

static void on_payment_failure(struct payment *payment)
{
struct payment *p;
struct payment *p, *nxt;
struct payment_tree_result result = payment_collect_result(payment);
list_for_each(&payments, p, list)
list_for_each_safe(&payments, p, nxt, list)
{
struct json_stream *ret;
struct command *cmd;
Expand Down

0 comments on commit da0b651

Please sign in to comment.