Commit 07ec9a0
authored
[discovery-proxy] restart query iteration to prevent heap UAF (#3367)
DiscoveryProxy::OnServiceDiscovered() and OnHostDiscovered()
iterate the OpenThread proxy-query list with otDnssdGetNextQuery()
while, inside the loop body, calling
otDnssdQueryHandleDiscoveredServiceInstance() or
otDnssdQueryHandleDiscoveredHost(). Those calls dequeue the current
query from the internal list and can heap-free the message depending
on the build configuration. The next iteration then dereferences the
stale pointer via query->GetNext() in otDnssdGetNextQuery(), causing
a heap use-after-free (UAF).
This commit fixes the issue by setting the query pointer to nullptr
after handling a query in the loops. Setting it to nullptr forces the
next loop iteration to restart scanning safely from the head of the
list. Because handled queries are always dequeued, the size of the
list always decreases, guaranteeing the loop will terminate without
accessing stale query pointers.1 parent fdb2607 commit 07ec9a0
1 file changed
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| 259 | + | |
259 | 260 | | |
260 | 261 | | |
261 | 262 | | |
| |||
310 | 311 | | |
311 | 312 | | |
312 | 313 | | |
| 314 | + | |
313 | 315 | | |
314 | 316 | | |
315 | 317 | | |
| |||
0 commit comments