fix memory safety: use-after-free in DHT, buffer overflows in TURN,

integer truncation
This commit is contained in:
2026-02-11 14:19:28 -03:00
parent 88a2abe521
commit 4770fad51c
4 changed files with 96 additions and 34 deletions

View File

@@ -336,6 +336,15 @@ pub fn disconnectPeerImpl(p2p: *P2P, peer_id: PeerId) Error!void {
p2p.allocator.destroy(socket);
}
// Clear DHT node-to-peer mapping to prevent stale identity spoofing on reconnect
{
p2p.dht_node_to_peer_mutex.lock();
defer p2p.dht_node_to_peer_mutex.unlock();
if (p2p.peer_to_dht_node.fetchRemove(peer_id)) |kv| {
_ = p2p.dht_node_to_peer.remove(kv.value);
}
}
// LEAK FIX: Also remove from peer_manager to free the address string
// Previously only removed from peer_connections, leaking the peer entry
if (p2p.peer_manager) |pm| {