mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
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:
parent
f716c55983
commit
c8c2c33952
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user