Skip to content

Commit

Permalink
cli: Add a JSON parsing sanity check before sending request
Browse files Browse the repository at this point in the history
If some parameter is malformed on the command line we could end up
with a malformed JSON-RPC request, which would then result in very
unhelpful error messages.

Fixes #4238
Changelog-Changed: cli: `lightning-cli` now performs better sanity checks on the JSON-RPC requests it sends.
  • Loading branch information
cdecker committed Dec 7, 2020
1 parent 0525253 commit a178680
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cli/lightning-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,14 @@ int main(int argc, char *argv[])
tal_append_fmt(&cmd, "] }");
}

toks = json_parse_simple(ctx, cmd, strlen(cmd));
if (toks == NULL)
errx(ERROR_USAGE,
"Some parameters are malformed, cannot create a valid "
"JSON-RPC request: %s",
cmd);
tal_free(toks);

if (!write_all(fd, cmd, strlen(cmd)))
err(ERROR_TALKING_TO_LIGHTNINGD, "Writing command");

Expand Down

0 comments on commit a178680

Please sign in to comment.