Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lightningd/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,13 @@ parse_request(struct json_connection *jcon,
"Expected string for method");
}

c->json_cmd = find_cmd(jcon->ld->jsonrpc, buffer, method);
if (!c->json_cmd) {
return command_fail(
c, JSONRPC2_METHOD_NOT_FOUND, "Unknown command '%.*s'",
method->end - method->start, buffer + method->start);
}

if (filter) {
struct command_result *ret;
ret = parse_filter(c, "filter", buffer, filter);
Expand All @@ -1081,12 +1088,6 @@ parse_request(struct json_connection *jcon,
* actually just logging the id */
log_io(jcon->log, LOG_IO_IN, NULL, c->id, NULL, 0);

c->json_cmd = find_cmd(jcon->ld->jsonrpc, buffer, method);
if (!c->json_cmd) {
return command_fail(
c, JSONRPC2_METHOD_NOT_FOUND, "Unknown command '%.*s'",
method->end - method->start, buffer + method->start);
}
if (!command_deprecated_in_ok(c, NULL,
c->json_cmd->depr_start,
c->json_cmd->depr_end)) {
Expand Down
24 changes: 24 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5042,3 +5042,27 @@ def test_zero_locktime_blocks(node_factory, bitcoind):
l2.rpc.close(l3.info['id'])
bitcoind.generate_block(1, wait_for_mempool=2)
sync_blockheight(bitcoind, [l1, l2, l3])


def test_filter_with_invalid_json(node_factory):
# This crashes only in *non-developer mode*: it uses command_log()
# in that case (since it doesn't print the invalid token in
# non-dev mode), and that expects cmd->json_cmd to be populated!`
l1 = node_factory.get_node(start=False)
l1.daemon.early_opts = []
l1.daemon.opts = {k: v for k, v in l1.daemon.opts.items() if not k.startswith('dev')}
l1.start()

out = subprocess.run(['cli/lightning-cli',
'--network={}'.format(TEST_NETWORK),
'--lightning-dir={}'
.format(l1.daemon.lightning_dir),
'-l', '1',
'-k',
'wait',
'subsystem=invoices',
'indexname=created',
'nextvalue=0'],
stdout=subprocess.PIPE)
assert 'filter: Expected object: invalid token' in out.stdout.decode('utf-8')
assert out.returncode == 1
Loading