Skip to content

Commit 3ce90f8

Browse files
lightningd: fix segfault when parse_filter fails
We need to initialize ->json_cmd *before* complaining about malformed filters. ``` lightningd: FATAL SIGNAL 11 (version v25.12-21-g3851187-modded) 0x1042d2023 ??? send_backtrace+0x4f:0 0x1042d20cb ??? crashdump+0x43:0 0x19fe3b743 ??? ???:0 0x104180173 command_log lightningd/jsonrpc.c:1406 0x10420d8f7 command_fail_badparam common/json_command.c:25 0x104181a07 parse_request lightningd/jsonrpc.c:1075 0x104181a07 read_json lightningd/jsonrpc.c:1216 0x10424c65b next_plan ccan/ccan/io/io.c:60 0x10424c65b do_plan ccan/ccan/io/io.c:422 0x10424c587 io_ready ccan/ccan/io/io.c:439 0x10424dd9b io_loop ccan/ccan/io/poll.c:470 0x10417ede7 io_loop_with_timers lightningd/io_loop_with_timers.c:22 0x104183a33 main lightningd/lightningd.c:1492 ``` Co-authored-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Fixed: JSON-RPC: malformed filters no longer crash lightningd.
1 parent cef11ea commit 3ce90f8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lightningd/jsonrpc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,13 @@ parse_request(struct json_connection *jcon,
10701070
"Expected string for method");
10711071
}
10721072

1073+
c->json_cmd = find_cmd(jcon->ld->jsonrpc, buffer, method);
1074+
if (!c->json_cmd) {
1075+
return command_fail(
1076+
c, JSONRPC2_METHOD_NOT_FOUND, "Unknown command '%.*s'",
1077+
method->end - method->start, buffer + method->start);
1078+
}
1079+
10731080
if (filter) {
10741081
struct command_result *ret;
10751082
ret = parse_filter(c, "filter", buffer, filter);
@@ -1081,12 +1088,6 @@ parse_request(struct json_connection *jcon,
10811088
* actually just logging the id */
10821089
log_io(jcon->log, LOG_IO_IN, NULL, c->id, NULL, 0);
10831090

1084-
c->json_cmd = find_cmd(jcon->ld->jsonrpc, buffer, method);
1085-
if (!c->json_cmd) {
1086-
return command_fail(
1087-
c, JSONRPC2_METHOD_NOT_FOUND, "Unknown command '%.*s'",
1088-
method->end - method->start, buffer + method->start);
1089-
}
10901091
if (!command_deprecated_in_ok(c, NULL,
10911092
c->json_cmd->depr_start,
10921093
c->json_cmd->depr_end)) {

0 commit comments

Comments
 (0)