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

Fix wrong size_t* to int* conversion in 64bit Big-Endian hosts (#637)

- Fixes #636
- Ensure that we have RTP or RTCP packet length into a `int` variable since `srtp_(un)protect_xxxx()` methods expect a pointer to `int` and modify the length referenced by the given pointer.
上级 b89f2d54
...@@ -36,10 +36,10 @@ namespace RTC ...@@ -36,10 +36,10 @@ namespace RTC
~SrtpSession(); ~SrtpSession();
public: public:
bool EncryptRtp(const uint8_t** data, size_t* len); bool EncryptRtp(const uint8_t** data, int* len);
bool DecryptSrtp(uint8_t* data, size_t* len); bool DecryptSrtp(uint8_t* data, int* len);
bool EncryptRtcp(const uint8_t** data, size_t* len); bool EncryptRtcp(const uint8_t** data, int* len);
bool DecryptSrtcp(uint8_t* data, size_t* len); bool DecryptSrtcp(uint8_t* data, int* len);
void RemoveStream(uint32_t ssrc) void RemoveStream(uint32_t ssrc)
{ {
srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) }); srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) });
......
...@@ -449,9 +449,9 @@ namespace RTC ...@@ -449,9 +449,9 @@ namespace RTC
} }
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
if (HasSrtp() && !this->srtpSendSession->EncryptRtp(&data, &len)) if (HasSrtp() && !this->srtpSendSession->EncryptRtp(&data, &intLen))
{ {
if (cb) if (cb)
{ {
...@@ -462,6 +462,8 @@ namespace RTC ...@@ -462,6 +462,8 @@ namespace RTC
return; return;
} }
auto len = static_cast<size_t>(intLen);
this->tuple->Send(data, len, cb); this->tuple->Send(data, len, cb);
// Increase send transmission. // Increase send transmission.
...@@ -476,11 +478,13 @@ namespace RTC ...@@ -476,11 +478,13 @@ namespace RTC
return; return;
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &len)) if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen))
return; return;
auto len = static_cast<size_t>(intLen);
this->tuple->Send(data, len); this->tuple->Send(data, len);
// Increase send transmission. // Increase send transmission.
...@@ -495,11 +499,13 @@ namespace RTC ...@@ -495,11 +499,13 @@ namespace RTC
return; return;
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &len)) if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen))
return; return;
auto len = static_cast<size_t>(intLen);
this->tuple->Send(data, len); this->tuple->Send(data, len);
// Increase send transmission. // Increase send transmission.
...@@ -583,9 +589,11 @@ namespace RTC ...@@ -583,9 +589,11 @@ namespace RTC
return; return;
// Decrypt the SRTP packet. // Decrypt the SRTP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast<uint8_t*>(data), &len)) auto intLen = static_cast<int>(len);
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast<uint8_t*>(data), &intLen))
{ {
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
...@@ -606,7 +614,7 @@ namespace RTC ...@@ -606,7 +614,7 @@ namespace RTC
return; return;
} }
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
...@@ -641,7 +649,9 @@ namespace RTC ...@@ -641,7 +649,9 @@ namespace RTC
return; return;
// Decrypt the SRTCP packet. // Decrypt the SRTCP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &len)) auto intLen = static_cast<int>(len);
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &intLen))
{ {
return; return;
} }
...@@ -654,7 +664,7 @@ namespace RTC ...@@ -654,7 +664,7 @@ namespace RTC
return; return;
} }
RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, len); RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
......
...@@ -634,9 +634,9 @@ namespace RTC ...@@ -634,9 +634,9 @@ namespace RTC
} }
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
if (HasSrtp() && !this->srtpSendSession->EncryptRtp(&data, &len)) if (HasSrtp() && !this->srtpSendSession->EncryptRtp(&data, &intLen))
{ {
if (cb) if (cb)
{ {
...@@ -647,6 +647,8 @@ namespace RTC ...@@ -647,6 +647,8 @@ namespace RTC
return; return;
} }
auto len = static_cast<size_t>(intLen);
this->tuple->Send(data, len, cb); this->tuple->Send(data, len, cb);
// Increase send transmission. // Increase send transmission.
...@@ -661,11 +663,13 @@ namespace RTC ...@@ -661,11 +663,13 @@ namespace RTC
return; return;
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &len)) if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen))
return; return;
auto len = static_cast<size_t>(intLen);
if (this->rtcpMux) if (this->rtcpMux)
this->tuple->Send(data, len); this->tuple->Send(data, len);
else if (this->rtcpTuple) else if (this->rtcpTuple)
...@@ -683,11 +687,13 @@ namespace RTC ...@@ -683,11 +687,13 @@ namespace RTC
return; return;
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &len)) if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen))
return; return;
auto len = static_cast<size_t>(intLen);
if (this->rtcpMux) if (this->rtcpMux)
this->tuple->Send(data, len); this->tuple->Send(data, len);
else if (this->rtcpTuple) else if (this->rtcpTuple)
...@@ -775,9 +781,11 @@ namespace RTC ...@@ -775,9 +781,11 @@ namespace RTC
return; return;
// Decrypt the SRTP packet. // Decrypt the SRTP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast<uint8_t*>(data), &len)) auto intLen = static_cast<int>(len);
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast<uint8_t*>(data), &intLen))
{ {
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
...@@ -798,7 +806,7 @@ namespace RTC ...@@ -798,7 +806,7 @@ namespace RTC
return; return;
} }
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
...@@ -871,7 +879,9 @@ namespace RTC ...@@ -871,7 +879,9 @@ namespace RTC
return; return;
// Decrypt the SRTCP packet. // Decrypt the SRTCP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &len)) auto intLen = static_cast<int>(len);
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &intLen))
{ {
return; return;
} }
...@@ -949,7 +959,7 @@ namespace RTC ...@@ -949,7 +959,7 @@ namespace RTC
return; return;
} }
RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, len); RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
......
...@@ -146,22 +146,21 @@ namespace RTC ...@@ -146,22 +146,21 @@ namespace RTC
} }
} }
bool SrtpSession::EncryptRtp(const uint8_t** data, size_t* len) bool SrtpSession::EncryptRtp(const uint8_t** data, int* len)
{ {
MS_TRACE(); MS_TRACE();
// Ensure that the resulting SRTP packet fits into the encrypt buffer. // Ensure that the resulting SRTP packet fits into the encrypt buffer.
if (*len + SRTP_MAX_TRAILER_LEN > EncryptBufferSize) if (static_cast<size_t>(*len) + SRTP_MAX_TRAILER_LEN > EncryptBufferSize)
{ {
MS_WARN_TAG(srtp, "cannot encrypt RTP packet, size too big (%zu bytes)", *len); MS_WARN_TAG(srtp, "cannot encrypt RTP packet, size too big (%i bytes)", *len);
return false; return false;
} }
std::memcpy(EncryptBuffer, *data, *len); std::memcpy(EncryptBuffer, *data, *len);
srtp_err_status_t err = srtp_err_status_t err = srtp_protect(this->session, static_cast<void*>(EncryptBuffer), len);
srtp_protect(this->session, static_cast<void*>(EncryptBuffer), reinterpret_cast<int*>(len));
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
...@@ -176,12 +175,11 @@ namespace RTC ...@@ -176,12 +175,11 @@ namespace RTC
return true; return true;
} }
bool SrtpSession::DecryptSrtp(uint8_t* data, size_t* len) bool SrtpSession::DecryptSrtp(uint8_t* data, int* len)
{ {
MS_TRACE(); MS_TRACE();
srtp_err_status_t err = srtp_err_status_t err = srtp_unprotect(this->session, static_cast<void*>(data), len);
srtp_unprotect(this->session, static_cast<void*>(data), reinterpret_cast<int*>(len));
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
...@@ -193,22 +191,21 @@ namespace RTC ...@@ -193,22 +191,21 @@ namespace RTC
return true; return true;
} }
bool SrtpSession::EncryptRtcp(const uint8_t** data, size_t* len) bool SrtpSession::EncryptRtcp(const uint8_t** data, int* len)
{ {
MS_TRACE(); MS_TRACE();
// Ensure that the resulting SRTCP packet fits into the encrypt buffer. // Ensure that the resulting SRTCP packet fits into the encrypt buffer.
if (*len + SRTP_MAX_TRAILER_LEN > EncryptBufferSize) if (static_cast<size_t>(*len) + SRTP_MAX_TRAILER_LEN > EncryptBufferSize)
{ {
MS_WARN_TAG(srtp, "cannot encrypt RTCP packet, size too big (%zu bytes)", *len); MS_WARN_TAG(srtp, "cannot encrypt RTCP packet, size too big (%i bytes)", *len);
return false; return false;
} }
std::memcpy(EncryptBuffer, *data, *len); std::memcpy(EncryptBuffer, *data, *len);
srtp_err_status_t err = srtp_protect_rtcp( srtp_err_status_t err = srtp_protect_rtcp(this->session, static_cast<void*>(EncryptBuffer), len);
this->session, static_cast<void*>(EncryptBuffer), reinterpret_cast<int*>(len));
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
...@@ -223,12 +220,11 @@ namespace RTC ...@@ -223,12 +220,11 @@ namespace RTC
return true; return true;
} }
bool SrtpSession::DecryptSrtcp(uint8_t* data, size_t* len) bool SrtpSession::DecryptSrtcp(uint8_t* data, int* len)
{ {
MS_TRACE(); MS_TRACE();
srtp_err_status_t err = srtp_err_status_t err = srtp_unprotect_rtcp(this->session, static_cast<void*>(data), len);
srtp_unprotect_rtcp(this->session, static_cast<void*>(data), reinterpret_cast<int*>(len));
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
......
...@@ -751,9 +751,9 @@ namespace RTC ...@@ -751,9 +751,9 @@ namespace RTC
} }
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
if (!this->srtpSendSession->EncryptRtp(&data, &len)) if (!this->srtpSendSession->EncryptRtp(&data, &intLen))
{ {
if (cb) if (cb)
{ {
...@@ -764,6 +764,8 @@ namespace RTC ...@@ -764,6 +764,8 @@ namespace RTC
return; return;
} }
auto len = static_cast<size_t>(intLen);
this->iceServer->GetSelectedTuple()->Send(data, len, cb); this->iceServer->GetSelectedTuple()->Send(data, len, cb);
// Increase send transmission. // Increase send transmission.
...@@ -778,7 +780,7 @@ namespace RTC ...@@ -778,7 +780,7 @@ namespace RTC
return; return;
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
// Ensure there is sending SRTP session. // Ensure there is sending SRTP session.
if (!this->srtpSendSession) if (!this->srtpSendSession)
...@@ -788,9 +790,11 @@ namespace RTC ...@@ -788,9 +790,11 @@ namespace RTC
return; return;
} }
if (!this->srtpSendSession->EncryptRtcp(&data, &len)) if (!this->srtpSendSession->EncryptRtcp(&data, &intLen))
return; return;
auto len = static_cast<size_t>(intLen);
this->iceServer->GetSelectedTuple()->Send(data, len); this->iceServer->GetSelectedTuple()->Send(data, len);
// Increase send transmission. // Increase send transmission.
...@@ -805,7 +809,7 @@ namespace RTC ...@@ -805,7 +809,7 @@ namespace RTC
return; return;
const uint8_t* data = packet->GetData(); const uint8_t* data = packet->GetData();
size_t len = packet->GetSize(); auto intLen = static_cast<int>(packet->GetSize());
// Ensure there is sending SRTP session. // Ensure there is sending SRTP session.
if (!this->srtpSendSession) if (!this->srtpSendSession)
...@@ -815,9 +819,11 @@ namespace RTC ...@@ -815,9 +819,11 @@ namespace RTC
return; return;
} }
if (!this->srtpSendSession->EncryptRtcp(&data, &len)) if (!this->srtpSendSession->EncryptRtcp(&data, &intLen))
return; return;
auto len = static_cast<size_t>(intLen);
this->iceServer->GetSelectedTuple()->Send(data, len); this->iceServer->GetSelectedTuple()->Send(data, len);
// Increase send transmission. // Increase send transmission.
...@@ -984,9 +990,11 @@ namespace RTC ...@@ -984,9 +990,11 @@ namespace RTC
} }
// Decrypt the SRTP packet. // Decrypt the SRTP packet.
if (!this->srtpRecvSession->DecryptSrtp(const_cast<uint8_t*>(data), &len)) auto intLen = static_cast<int>(len);
if (!this->srtpRecvSession->DecryptSrtp(const_cast<uint8_t*>(data), &intLen))
{ {
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
...@@ -1007,7 +1015,7 @@ namespace RTC ...@@ -1007,7 +1015,7 @@ namespace RTC
return; return;
} }
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
...@@ -1053,10 +1061,12 @@ namespace RTC ...@@ -1053,10 +1061,12 @@ namespace RTC
} }
// Decrypt the SRTCP packet. // Decrypt the SRTCP packet.
if (!this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &len)) auto intLen = static_cast<int>(len);
if (!this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &intLen))
return; return;
RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, len); RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, static_cast<size_t>(intLen));
if (!packet) if (!packet)
{ {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论