Skip to content

Commit

Permalink
jsonrpc: Forward errors on malformed requests to cli
Browse files Browse the repository at this point in the history
We were masquerading errors when parsing the request by reporting only
a bogus malformed `id` field in the response, when the real issue was
that we were unable to parse the request in the first place (which
caused the null-id error to be returned).

Fixes ElementsProject#4238
  • Loading branch information
cdecker committed Dec 8, 2020
1 parent e80f298 commit 2652fae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cli/lightning-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,9 @@ int main(int argc, char *argv[])
"Missing 'id' in response '%s'", resp);
if (!json_tok_streq(resp, id, idstr))
errx(ERROR_TALKING_TO_LIGHTNINGD,
"Incorrect 'id' in response: %.*s",
json_tok_full_len(id), json_tok_full(resp, id));
"Incorrect 'id' (%.*s) in response: %.*s",
json_tok_full_len(id), json_tok_full(resp, id),
json_tok_full_len(toks), json_tok_full(resp, toks));

if (!error || json_tok_is_null(resp, error)) {
switch (format) {
Expand Down
6 changes: 4 additions & 2 deletions lightningd/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,10 @@ static struct io_plan *read_json(struct io_conn *conn,
if (!json_parse_input(&jcon->input_parser, &jcon->input_toks,
jcon->buffer, jcon->used,
&complete)) {
json_command_malformed(jcon, "null",
"Invalid token in json input");
json_command_malformed(
jcon, "null",
tal_fmt(tmpctx, "Invalid token in json input: '%s'",
tal_strndup(tmpctx, jcon->buffer, jcon->used)));
return io_halfclose(conn);
}

Expand Down

0 comments on commit 2652fae

Please sign in to comment.