Skip to content

Commit 3291b77

Browse files
committed
[nrf fromtree] net: dns: dispatcher: Don't use uninitialized entries
In case CONFIG_DNS_RESOLVER_MAX_SERVERS is larger than the actual number of DNS servers configured, some server entries may be left uninitialized. The dispatcher needs to take this into account, otherwise it may cause memory corruptions. Signed-off-by: Robert Lubos <[email protected]> (cherry picked from commit 5c6b003)
1 parent 518dfc6 commit 3291b77

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

subsys/net/lib/dns/dispatcher.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ int dns_dispatcher_register(struct dns_socket_dispatcher *ctx)
240240
goto out;
241241
}
242242

243+
if (ctx->fds[i].fd < 0) {
244+
continue;
245+
}
246+
243247
if (dispatch_table[ctx->fds[i].fd].ctx == NULL) {
244248
dispatch_table[ctx->fds[i].fd].ctx = ctx;
245249
}
@@ -277,6 +281,10 @@ int dns_dispatcher_register(struct dns_socket_dispatcher *ctx)
277281
goto out;
278282
}
279283

284+
if (ctx->fds[i].fd < 0) {
285+
continue;
286+
}
287+
280288
if (dispatch_table[ctx->fds[i].fd].ctx == NULL) {
281289
dispatch_table[ctx->fds[i].fd].ctx = ctx;
282290
}

0 commit comments

Comments
 (0)