Skip to content

Commit

Permalink
net: dns: dispatcher: Don't use uninitialized entires
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rlubos committed Oct 3, 2024
1 parent ff5fe19 commit 0ed6617
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions subsys/net/lib/dns/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ int dns_dispatcher_register(struct dns_socket_dispatcher *ctx)
goto out;
}

if (ctx->fds[i].fd < 0) {
continue;
}

if (dispatch_table[ctx->fds[i].fd].ctx == NULL) {
dispatch_table[ctx->fds[i].fd].ctx = ctx;
}
Expand Down Expand Up @@ -297,6 +301,10 @@ int dns_dispatcher_register(struct dns_socket_dispatcher *ctx)
goto out;
}

if (ctx->fds[i].fd < 0) {
continue;
}

if (dispatch_table[ctx->fds[i].fd].ctx == NULL) {
dispatch_table[ctx->fds[i].fd].ctx = ctx;
}
Expand Down

0 comments on commit 0ed6617

Please sign in to comment.