plugin: Prevent plugins from registering native notification topics

They may already have subscribers, and they may crash if presented
with a malformed notification.
This commit is contained in:
Christian Decker 2021-04-28 15:58:46 +02:00 committed by Rusty Russell
parent f716c55983
commit c8c2c33952
3 changed files with 19 additions and 2 deletions

View File

@ -18,10 +18,15 @@ static struct notification *find_notification_by_topic(const char* topic)
return NULL;
}
bool notifications_have_topic(const struct plugins *plugins, const char *topic)
bool notifications_topic_is_native(const char *topic)
{
struct notification *noti = find_notification_by_topic(topic);
if (noti)
return noti != NULL;
}
bool notifications_have_topic(const struct plugins *plugins, const char *topic)
{
if (notifications_topic_is_native(topic))
return true;
/* Some plugin at some point announced it'd be emitting

View File

@ -27,6 +27,10 @@ struct wally_psbt;
bool notifications_have_topic(const struct plugins *plugins, const char *topic);
/* Is the provided notification topic native, i.e., provided by
* lightningd itself? */
bool notifications_topic_is_native(const char *topic);
struct notification {
const char *topic;
/* the serialization interface */

View File

@ -1327,6 +1327,14 @@ static const char *plugin_notifications_add(const char *buffer,
i);
name = json_strdup(plugin->plugins, buffer, method);
if (notifications_topic_is_native(name))
return tal_fmt(plugin,
"plugin attempted to register a native "
"notification topic \"%s\", these may "
"however only be sent by lightningd",
name);
tal_arr_expand(&plugin->plugins->notification_topics, name);
}