Skip to content

Commit 0f1d7d3

Browse files
JordanYateskartben
authored andcommitted
net: dns: dispatcher: fix OOB array access
Validate that the file descriptor is not a negative number before writing to the `dispatch_table` `ctx` field. Setting file descriptors to `-1` is the standard "not in use" value, and in fact the entire array of `fds` is set to this value in `dns_resolve_init_locked`. This resolves memory corruption of whichever variable is unfortunate to exist just before `dispatch_table` in memory. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 2e484fc commit 0f1d7d3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

subsys/net/lib/dns/dispatcher.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ int dns_dispatcher_unregister(struct dns_socket_dispatcher *ctx)
345345
goto out;
346346
}
347347

348+
if (ctx->fds[i].fd < 0) {
349+
continue;
350+
}
351+
348352
dispatch_table[ctx->fds[i].fd].ctx = NULL;
349353
}
350354

0 commit comments

Comments
 (0)