libp2p / cpp-libp2p

C++17 implementation of libp2p
Apache License 2.0
347 stars 98 forks source link

PeerContext is used after being deleted, keep shared pointer to it. #161

Closed Alexey-N-Chernyshov closed 2 years ago

Alexey-N-Chernyshov commented 2 years ago

ASAN found 'heap-use-after-free' in gossip (link).

There is circular dependency in Stream and PeerContext. Stream is passed as a weak pointer and is not locked here and PeerContext is passed as a const ref here. So, after shared pointer to Stream is reset, the Stream and PeerContext are deleted and than the attempt to read here is made. This PR keeps shared pointer to PeerContext.