Unverified 提交 bd1b4345 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Fix SIGSEGV at RTC::WebRtcTransport::OnIceServerTupleRemoved() (#915)

- Fixes #883
- `IceServer` manages a list of `TransportTuples` instances in a `std::list`. Those are **not** pointers.
- When `IceServer` removes a tuple from the list (for different reasons), it removes it from its `std::list`, which means that the removed `TransportTuple` is **freed**. And then it notifies `WebRtcTransport` via `this->listener->OnIceServerTupleRemoved(this, removedTuple);`. Problem was that `WebRtcTransport` reads tuple data (`tuple->GetProtocol()` etc) so it's doing that in an already freed memory!, so crash.
- Solution is to first notify the listener (`WebRtcTransport`) then remove it from the list (so free it after used).
上级 b2b0f3c3
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
### Next ### Next
* Fix SIGSEGV at `RTC::WebRtcTransport::OnIceServerTupleRemoved()` (PR #915, credits to @ybybwdwd).
### 3.10.7 ### 3.10.7
......
...@@ -46,6 +46,8 @@ namespace RTC ...@@ -46,6 +46,8 @@ namespace RTC
// Notify the listener. // Notify the listener.
this->listener->OnIceServerTupleRemoved(this, storedTuple); this->listener->OnIceServerTupleRemoved(this, storedTuple);
} }
this->tuples.clear();
} }
void IceServer::ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple) void IceServer::ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple)
...@@ -294,7 +296,12 @@ namespace RTC ...@@ -294,7 +296,12 @@ namespace RTC
if (!removedTuple) if (!removedTuple)
return; return;
// Notify the listener.
this->listener->OnIceServerTupleRemoved(this, removedTuple);
// Remove it from the list of tuples. // Remove it from the list of tuples.
// NOTE: Do it after notifying the listener since the listener may need to
// use/read the tuple being removed so we cannot free it yet.
this->tuples.erase(it); this->tuples.erase(it);
// If this is the selected tuple, do things. // If this is the selected tuple, do things.
...@@ -316,9 +323,6 @@ namespace RTC ...@@ -316,9 +323,6 @@ namespace RTC
this->listener->OnIceServerDisconnected(this); this->listener->OnIceServerDisconnected(this);
} }
} }
// Notify the listener.
this->listener->OnIceServerTupleRemoved(this, removedTuple);
} }
void IceServer::ForceSelectedTuple(const RTC::TransportTuple* tuple) void IceServer::ForceSelectedTuple(const RTC::TransportTuple* tuple)
...@@ -591,13 +595,15 @@ namespace RTC ...@@ -591,13 +595,15 @@ namespace RTC
// This should not happen by design. // This should not happen by design.
MS_ASSERT(removedTuple, "couldn't find any tuple to be removed"); MS_ASSERT(removedTuple, "couldn't find any tuple to be removed");
// Notify the listener.
this->listener->OnIceServerTupleRemoved(this, removedTuple);
// Remove it from the list of tuples. // Remove it from the list of tuples.
// NOTE: Do it after notifying the listener since the listener may need to
// use/read the tuple being removed so we cannot free it yet.
// NOTE: This trick is needed since it is a reverse_iterator and // NOTE: This trick is needed since it is a reverse_iterator and
// erase() requires a iterator, const_iterator or bidirectional_iterator. // erase() requires a iterator, const_iterator or bidirectional_iterator.
this->tuples.erase(std::next(it).base()); this->tuples.erase(std::next(it).base());
// Notify the listener.
this->listener->OnIceServerTupleRemoved(this, removedTuple);
} }
// Return the address of the inserted tuple. // Return the address of the inserted tuple.
......
...@@ -1278,7 +1278,9 @@ namespace RTC ...@@ -1278,7 +1278,9 @@ namespace RTC
// If this is a TCP tuple, close its underlaying TCP connection. // If this is a TCP tuple, close its underlaying TCP connection.
if (tuple->GetProtocol() == RTC::TransportTuple::Protocol::TCP && !tuple->IsClosed()) if (tuple->GetProtocol() == RTC::TransportTuple::Protocol::TCP && !tuple->IsClosed())
{
tuple->Close(); tuple->Close();
}
} }
inline void WebRtcTransport::OnIceServerSelectedTuple( inline void WebRtcTransport::OnIceServerSelectedTuple(
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论