ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.86k stars 905 forks source link

bug: `cln-plugin` cannot properly parse IP addresses #6795

Open sr-gi opened 1 year ago

sr-gi commented 1 year ago

Looks like IP addresses passed to lightning-cli through cln-plugin are interpreted as numbers instead of strings, making the plugin manager fail to parse them and, therefore, crashing the plugin.

This applies to all possible ways to pass the argument as long it is passed by itself, that is, by position and by key, but not formatted in a string with other values such as "id@ip:port".

Notice this does not only apply to IPs, but also to any value formatted like x.y.z where {x, y, z} $\in N$. The reason seems to be that the backend interprets x. as a number, no matter what comes after.

How to reproduce

This can be easily tested by passing an IP to lightning-cli using a plugin that uses the rustlang plugin library. You can find a minimal reproducible example at: https://github.com/sr-gi/cln-passip.

In order to reproduce this you simply need to add cln-passip as a plugin and call:

lightning-cli passip 1.2.3.4

Or any other combination of dotted values provided the expression has more than one dot.

cdecker commented 1 year ago

It should be noted that this is not cln-plugin-related, rather it is the lightning-cli misidentifying the IP address as a float, thus omitting the " quotes and therefore producing invalid JSON.

We need to update the type-inference in lightning-cli to fix this, and it should already work correctly when called via anything else that returns valid JSON messages.