Browse Source

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

ppa-0.6.1
Corné Plooy 7 years ago
committed by Christian Decker
parent
commit
1e879de89e
  1. 10
      lightningd/jsonrpc.c

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

Loading…
Cancel
Save