From 1e879de89e52be200ceba87f05af12ceef95c04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corn=C3=A9=20Plooy?= Date: Wed, 28 Feb 2018 11:01:09 +0100 Subject: [PATCH] json-rpc: connection_complete_ok and json_command_malformed should never receive NULL arguments. Pass "null" instead, where needed. --- lightningd/jsonrpc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 86f158c8e..22171f620 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -263,6 +263,8 @@ static void connection_complete_ok(struct json_connection *jcon, const char *id, const struct json_result *result) { + assert(id != NULL); + /* This JSON is simple enough that we build manually */ json_done(jcon, cmd, take(tal_fmt(jcon, "{ \"jsonrpc\": \"2.0\", " @@ -290,11 +292,7 @@ static void connection_complete_error(struct json_connection *jcon, else data_str = ""; - /* - tal_fmt translates NULL into "(null)", which is not valid JSON. - Prevent this by pre-emptively translating NULL into "null". - */ - if(id == NULL) id = "null"; + assert(id != NULL); json_done(jcon, cmd, take(tal_fmt(tmpctx, "{ \"jsonrpc\": \"2.0\", " @@ -691,7 +689,7 @@ again: "Invalid token in json input: '%.*s'", (int)jcon->used, jcon->buffer); json_command_malformed( - jcon, NULL, + jcon, "null", "Invalid token in json input"); return io_halfclose(conn); }