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

May fix DTLS related crash (issue #861) (#867)

* Fix DTLS related crash (issue #861)
上级 49cfeeaa
......@@ -980,28 +980,25 @@ namespace RTC
{
MS_TRACE();
MS_ASSERT(this->ssl, "this->ssl is not set");
MS_ASSERT(
this->state == DtlsState::CONNECTING || this->state == DtlsState::CONNECTED,
"invalid DTLS state");
int64_t ret;
uv_timeval_t dtlsTimeout{ 0, 0 };
uint64_t timeoutMs;
// NOTE: No DTLSv_1_2_get_timeout() or DTLS_get_timeout() in OpenSSL 1.1.0-dev.
ret = DTLSv1_get_timeout(this->ssl, static_cast<void*>(&dtlsTimeout)); // NOLINT
if (ret == 0)
{
OnTimer(this->timer);
return true;
}
// DTLSv1_get_timeout queries the next DTLS handshake timeout. If there is
// a timeout in progress, it sets *out to the time remaining and returns
// one. Otherwise, it returns zero.
DTLSv1_get_timeout(this->ssl, static_cast<void*>(&dtlsTimeout)); // NOLINT
timeoutMs = (dtlsTimeout.tv_sec * static_cast<uint64_t>(1000)) + (dtlsTimeout.tv_usec / 1000);
if (timeoutMs == 0)
{
MS_DEBUG_DEV("timeout is 0, calling OnTimer() callback directly");
OnTimer(this->timer);
return true;
......@@ -1424,11 +1421,21 @@ namespace RTC
return;
}
// DTLSv1_handle_timeout is called when a DTLS handshake timeout expires.
// If no timeout had expired, it returns 0. Otherwise, it retransmits the
// previous flight of handshake messages and returns 1. If too many timeouts
// had expired without progress or an error occurs, it returns -1.
auto ret = DTLSv1_handle_timeout(this->ssl);
// -1 means that too many timeouts had expired without progress or an
// error occurs.
if (ret == -1)
if (ret == 1)
{
// If required, send DTLS data.
SendPendingOutgoingDtlsData();
// Set the DTLS timer again.
SetTimeout();
}
else if (ret == -1)
{
MS_WARN_TAG(dtls, "DTLSv1_handle_timeout() failed");
......@@ -1438,13 +1445,5 @@ namespace RTC
this->state = DtlsState::FAILED;
this->listener->OnDtlsTransportFailed(this);
}
else
{
// If required, send DTLS data.
SendPendingOutgoingDtlsData();
// Set the DTLS timer again.
SetTimeout();
}
}
} // namespace RTC
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论