Browse Source

cli: Add a JSON parsing sanity check before sending request

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.
fix-mocks
Christian Decker 4 years ago
committed by Rusty Russell
parent
commit
ad2f6cdabb
  1. 8
      cli/lightning-cli.c

8
cli/lightning-cli.c

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

Loading…
Cancel
Save