Skip to content

Commit

Permalink
lightningd: refuse to create rune with empty fields.
Browse files Browse the repository at this point in the history
These look like uniqueids, and so can confuse us (I discovered this by
making a typo in a test!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Sep 12, 2023
1 parent bb38f83 commit ecb0977
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lightningd/runes.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ static struct rune_altern *rune_altern_from_json(const tal_t *ctx,
alt->fieldname = tal_strndup(alt, unescape, condoff);
alt->condition = unescape[condoff];
alt->value = tal_strdup(alt, unescape + condoff + 1);

/* don't let them add empty fieldnames */
if (streq(alt->fieldname, ""))
return tal_free(alt);
return alt;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/test_runes.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,14 @@ def test_missing_method_or_nodeid(node_factory):
l1.rpc.checkrune(rune=rune4, nodeid=l1.info['id'])


def test_invalid_restrictions(node_factory):
# I meant "method!" not "!method"!
l1 = node_factory.get_node()
for cond in "!=/^$~<>{}#,":
with pytest.raises(RpcError, match='not a valid restriction'):
print(l1.rpc.createrune(restrictions=[[f"{cond}method"]]))


def test_showrune_id(node_factory):
l1 = node_factory.get_node()

Expand Down

0 comments on commit ecb0977

Please sign in to comment.