From 95c59e103548e45d73ad0bfd368c6af7a9e0baea Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Thu, 21 May 2026 12:36:18 +0200 Subject: [PATCH] MT#61856 control_ng: init err response to dict by default In case the data length is <= 0, or there has been no dictionary-like or json-like format spotted in the NG incoming control message, then treat parser as native (so dict) by default. Otherwise not possible to initilize the command context, and hence the error treatment wouldn't be able to prepare the response properly. Change-Id: I99b9c571a9112a25e474dfc39e21cce15fc5f634 --- daemon/control_ng.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/daemon/control_ng.c b/daemon/control_ng.c index b2516557a..116b6c443 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -703,8 +703,13 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons command_ctx.ngbuf = *ngbufp = ng_buffer_new(ref); errstr = "Invalid data (no payload)"; - if (data->len <= 0) - goto err_send; // TODO: the `command_ctx.resp` isn't initialized yet, fix? + if (data->len <= 0) { + ng_parser_native.init(&command_ctx.parser_ctx, &command_ctx.ngbuf->buffer); + command_ctx.resp = parser->dict(&command_ctx.parser_ctx); // init as dict by default + assert(command_ctx.resp.gen != NULL); + + goto err_send; + } /* Bencode dictionary */ if (data->s[0] == 'd') { @@ -739,8 +744,12 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons } else { + ng_parser_native.init(&command_ctx.parser_ctx, &command_ctx.ngbuf->buffer); + command_ctx.resp = parser->dict(&command_ctx.parser_ctx); // init as dict by default + assert(command_ctx.resp.gen != NULL); + errstr = "Invalid NG data format"; - goto err_send; // TODO: the `command_ctx.resp` isn't initialized yet, fix? + goto err_send; } parser = command_ctx.parser_ctx.parser;