Skip to content

Commit 07ec9a0

Browse files
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

File tree

src/sdp_proxy/discovery_proxy.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void DiscoveryProxy::OnServiceDiscovered(const std::string
256256
instanceInfo.mHostName = translatedHostName.c_str();
257257

258258
otDnssdQueryHandleDiscoveredServiceInstance(mHost.GetInstance(), serviceFullName.c_str(), &instanceInfo);
259+
query = nullptr;
259260
}
260261
}
261262
}
@@ -310,6 +311,7 @@ void DiscoveryProxy::OnHostDiscovered(const std::string
310311
std::string hostFullName = TranslateDomain(resolvedHostName, domain);
311312

312313
otDnssdQueryHandleDiscoveredHost(mHost.GetInstance(), hostFullName.c_str(), &hostInfo);
314+
query = nullptr;
313315
}
314316
}
315317

0 commit comments

Comments
 (0)