json-rpc: connection_complete_ok and json_command_malformed should never receive NULL arguments. Pass "null" instead, where needed.

This commit is contained in:
Corné Plooy 2018-02-28 11:01:09 +01:00 committed by Christian Decker
parent d86ad15b53
commit 1e879de89e

View File

@ -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);
}