lib: updatehub: Fix out-of-bounds access

The struct pollfd context variable is not proper initialized and index
is out-of-bounds. Adjusts index to be inside scope boundary.

Fixes #26993.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
This commit is contained in:
Gerson Fernando Budke 2020-07-28 23:24:06 -03:00 committed by Carles Cufí
commit 8683b47b17

View file

@ -216,11 +216,16 @@ static bool start_coap_client(void)
static void cleanup_connection(void)
{
int i;
if (close(ctx.sock) < 0) {
LOG_ERR("Could not close the socket");
}
memset(&ctx.fds[1], 0, sizeof(ctx.fds[1]));
for (i = 0; i < ctx.nfds; i++) {
memset(&ctx.fds[i], 0, sizeof(ctx.fds[i]));
}
ctx.nfds = 0;
ctx.sock = 0;
}
@ -738,6 +743,8 @@ enum updatehub_response updatehub_probe(void)
goto error;
}
ctx.nfds = 0;
if (!start_coap_client()) {
ctx.code_status = UPDATEHUB_NETWORKING_ERROR;
goto error;