mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
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.
This commit is contained in:
parent
b2a5cf422f
commit
ad2f6cdabb
@ -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…
Reference in New Issue
Block a user