mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +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:
committed by
Rusty Russell
parent
f716c55983
commit
c8c2c33952
@@ -18,10 +18,15 @@ static struct notification *find_notification_by_topic(const char* topic)
|
|||||||
return NULL;
|
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);
|
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;
|
return true;
|
||||||
|
|
||||||
/* Some plugin at some point announced it'd be emitting
|
/* 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);
|
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 {
|
struct notification {
|
||||||
const char *topic;
|
const char *topic;
|
||||||
/* the serialization interface */
|
/* the serialization interface */
|
||||||
|
|||||||
@@ -1327,6 +1327,14 @@ static const char *plugin_notifications_add(const char *buffer,
|
|||||||
i);
|
i);
|
||||||
|
|
||||||
name = json_strdup(plugin->plugins, buffer, method);
|
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);
|
tal_arr_expand(&plugin->plugins->notification_topics, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user