Skip to content

Commit

Permalink
[core] Protecting RCV buffer access (#1335)
Browse files Browse the repository at this point in the history
Together with #1333 fixes #486
  • Loading branch information
maxsharabayko authored Jun 11, 2020
1 parent e03dbc6 commit 903e023
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6918,7 +6918,9 @@ int CUDT::receiveMessage(char* data, int len, SRT_MSGCTRL& w_mctrl, int by_excep
if (m_bBroken || m_bClosing)
{
HLOGC(mglog.Debug, log << CONID() << "receiveMessage: CONNECTION BROKEN - reading from recv buffer just for formality");
enterCS(m_RcvBufferLock);
int res = m_pRcvBuffer->readMsg(data, len);
leaveCS(m_RcvBufferLock);
w_mctrl.srctime = 0;

// Kick TsbPd thread to schedule next wakeup (if running)
Expand Down Expand Up @@ -6956,8 +6958,9 @@ int CUDT::receiveMessage(char* data, int len, SRT_MSGCTRL& w_mctrl, int by_excep
if (!m_bSynRecving)
{
HLOGC(dlog.Debug, log << CONID() << "receiveMessage: BEGIN ASYNC MODE. Going to extract payload size=" << len);

int res = m_pRcvBuffer->readMsg(data, len, (w_mctrl), seqdistance);
enterCS(m_RcvBufferLock);
const int res = m_pRcvBuffer->readMsg(data, len, (w_mctrl), seqdistance);
leaveCS(m_RcvBufferLock);
HLOGC(dlog.Debug, log << CONID() << "AFTER readMsg: (NON-BLOCKING) result=" << res);

if (res == 0)
Expand Down Expand Up @@ -7020,7 +7023,7 @@ int CUDT::receiveMessage(char* data, int len, SRT_MSGCTRL& w_mctrl, int by_excep
{
steady_clock::time_point tstime SRT_ATR_UNUSED;
int32_t seqno;
if (stillConnected() && !timeout && (!m_pRcvBuffer->isRcvDataReady((tstime), (seqno), seqdistance)))
if (stillConnected() && !timeout && !m_pRcvBuffer->isRcvDataReady((tstime), (seqno), seqdistance))
{
/* Kick TsbPd thread to schedule next wakeup (if running) */
if (m_bTsbPd)
Expand Down Expand Up @@ -7073,7 +7076,9 @@ int CUDT::receiveMessage(char* data, int len, SRT_MSGCTRL& w_mctrl, int by_excep
<< " NMSG " << m_pRcvBuffer->getRcvMsgNum());
*/

enterCS(m_RcvBufferLock);
res = m_pRcvBuffer->readMsg((data), len, (w_mctrl), seqdistance);
leaveCS(m_RcvBufferLock);
HLOGC(dlog.Debug, log << CONID() << "AFTER readMsg: (BLOCKING) result=" << res);

if (m_bBroken || m_bClosing)
Expand Down
2 changes: 1 addition & 1 deletion srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ class CUDT
srt::sync::Mutex m_RecvDataLock; // lock associated to m_RecvDataCond

srt::sync::Mutex m_SendLock; // used to synchronize "send" call
srt::sync::Mutex m_RecvLock; // used to synchronize "recv" call
srt::sync::Mutex m_RecvLock; // used to synchronize "recv" call, protects TSBPD drift updates (CRcvBuffer::isRcvDataReady())
srt::sync::Mutex m_RcvLossLock; // Protects the receiver loss list (access: CRcvQueue::worker, CUDT::tsbpd)
srt::sync::Mutex m_StatsLock; // used to synchronize access to trace statistics

Expand Down

0 comments on commit 903e023

Please sign in to comment.