From d3c312860ddfb18e0c71a7bbe455fc92f0dffe7a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 16 Apr 2019 09:40:07 +0930 Subject: [PATCH] lightningd: if a plugin gives a JSON-RPC error, print it. We currently just segfault when the deserialize function to access resulttok. Signed-off-by: Rusty Russell --- lightningd/plugin_hook.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index d762139d3..acf1c4783 100644 --- a/lightningd/plugin_hook.c +++ b/lightningd/plugin_hook.c @@ -53,7 +53,14 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks, struct plugin_hook_request *r) { const jsmntok_t *resulttok = json_get_member(buffer, toks, "result"); - void *response = r->hook->deserialize_response(r, buffer, resulttok); + void *response; + + if (!resulttok) + fatal("Plugin for %s returned non-result response %.*s", + r->hook->name, + toks->end - toks->start, buffer + toks->end); + + response = r->hook->deserialize_response(r, buffer, resulttok); db_begin_transaction(r->db); r->hook->response_cb(r->cb_arg, response); db_commit_transaction(r->db);