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
mr26.1
Donat Zenichev 4 weeks ago
parent bb8b91e1b0
commit 95c59e1035

@ -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;

Loading…
Cancel
Save