diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 06f6e4a86..a7f78a8bd 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -78,6 +78,9 @@ static void json_stop(struct command *cmd, { struct json_result *response = new_json_result(cmd); + if (!param(cmd, buffer, params, NULL)) + return; + /* This can't have closed yet! */ cmd->jcon->stop = true; json_add_string(response, NULL, "Shutting down"); @@ -121,6 +124,9 @@ AUTODATA(json_command, &dev_rhash_command); static void json_crash(struct command *cmd UNUSED, const char *buffer UNUSED, const jsmntok_t *params UNUSED) { + if (!param(cmd, buffer, params, NULL)) + return; + fatal("Crash at user request"); } @@ -137,6 +143,9 @@ static void json_getinfo(struct command *cmd, { struct json_result *response = new_json_result(cmd); + if (!param(cmd, buffer, params, NULL)) + return; + json_object_start(response, NULL); json_add_pubkey(response, "id", &cmd->ld->id); json_add_string(response, "alias", (const char *)cmd->ld->alias); diff --git a/lightningd/memdump.c b/lightningd/memdump.c index 5e9914c00..e8b9f6bb1 100644 --- a/lightningd/memdump.c +++ b/lightningd/memdump.c @@ -10,6 +10,7 @@ #include #include #include +#include #include static void json_add_ptr(struct json_result *response, const char *name, @@ -57,6 +58,9 @@ static void json_memdump(struct command *cmd, { struct json_result *response = new_json_result(cmd); + if (!param(cmd, buffer, params, NULL)) + return; + add_memdump(response, NULL, NULL, cmd); command_success(cmd, response); @@ -151,6 +155,9 @@ static void json_memleak(struct command *cmd, { struct json_result *response = new_json_result(cmd); + if (!param(cmd, buffer, params, NULL)) + return; + if (!getenv("LIGHTNINGD_DEV_MEMLEAK")) { command_fail(cmd, LIGHTNINGD, "Leak detection needs $LIGHTNINGD_DEV_MEMLEAK"); diff --git a/lightningd/test/run-param.c b/lightningd/test/run-param.c index 7b069deb0..8e735fdc2 100644 --- a/lightningd/test/run-param.c +++ b/lightningd/test/run-param.c @@ -253,6 +253,16 @@ static void null_params(void) assert(*intptrs[6] == 888); } +static void no_params(void) +{ + struct json *j = json_parse(cmd, "[]"); + assert(param(cmd, j->buffer, j->toks, NULL)); + + j = json_parse(cmd, "[ 'unexpected' ]"); + assert(!param(cmd, j->buffer, j->toks, NULL)); +} + + #if DEVELOPER /* * Check to make sure there are no programming mistakes. @@ -560,12 +570,14 @@ int main(void) setup_locale(); setup_tmpctx(); cmd = tal(tmpctx, struct command); + cmd->mode = CMD_NORMAL; fail_msg = tal_arr(cmd, char, 10000); zero_params(); sanity(); tok_tok(); null_params(); + no_params(); #if DEVELOPER bad_programmer(); #endif diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 2e0ad1c1f..69372eeb6 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -388,6 +388,10 @@ static void json_listfunds(struct command *cmd, const char *buffer UNUSED, wallet_get_utxos(cmd, cmd->ld->wallet, output_state_available); char* out; struct pubkey funding_pubkey; + + if (!param(cmd, buffer, params, NULL)) + return; + json_object_start(response, NULL); json_array_start(response, "outputs"); for (size_t i = 0; i < tal_count(utxos); i++) { @@ -505,6 +509,10 @@ static void json_dev_rescan_outputs(struct command *cmd, const jsmntok_t *params UNUSED) { struct txo_rescan *rescan = tal(cmd, struct txo_rescan); + + if (!param(cmd, buffer, params, NULL)) + return; + rescan->response = new_json_result(cmd); rescan->cmd = cmd;