Skip to content

Commit

Permalink
[core] Fixed SRTO_MINVERSION didn't reject too old version (#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored Oct 12, 2020
1 parent f646ef8 commit ca79ad9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
21 changes: 18 additions & 3 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ CUDT::CUDT(CUDTSocket* parent, const CUDT& ancestor): m_parent(parent)
// but not the underlying congctl object. After
// copy-constructed, the 'configure' must be called on it again.
m_CongCtl = ancestor.m_CongCtl;

m_lSrtVersion = ancestor.m_lSrtVersion;
m_lMinimumPeerSrtVersion = ancestor.m_lMinimumPeerSrtVersion;
}

CUDT::~CUDT()
Expand Down Expand Up @@ -2583,7 +2586,7 @@ int CUDT::processSrtMsg_HSREQ(const uint32_t *srtdata, size_t bytelen, uint32_t

HLOGC(cnlog.Debug,
log << "HSREQ/rcv: PEER Version: " << SrtVersionString(m_lPeerSrtVersion) << " Flags: " << m_lPeerSrtFlags
<< "(" << SrtFlagString(m_lPeerSrtFlags) << ")");
<< "(" << SrtFlagString(m_lPeerSrtFlags) << ") Min req version:" << SrtVersionString(m_lMinimumPeerSrtVersion));

m_bPeerRexmitFlag = IsSet(m_lPeerSrtFlags, SRT_OPT_REXMITFLG);
HLOGF(cnlog.Debug, "HSREQ/rcv: peer %s REXMIT flag", m_bPeerRexmitFlag ? "UNDERSTANDS" : "DOES NOT UNDERSTAND");
Expand Down Expand Up @@ -2773,6 +2776,16 @@ int CUDT::processSrtMsg_HSRSP(const uint32_t *srtdata, size_t bytelen, uint32_t
m_lPeerSrtFlags,
SrtFlagString(m_lPeerSrtFlags).c_str());

// Basic version check
if (m_lPeerSrtVersion < m_lMinimumPeerSrtVersion)
{
m_RejectReason = SRT_REJ_VERSION;
LOGC(cnlog.Error,
log << "HSRSP/rcv: Peer version: " << SrtVersionString(m_lPeerSrtVersion)
<< " is too old for requested: " << SrtVersionString(m_lMinimumPeerSrtVersion) << " - REJECTING");
return SRT_CMD_REJECT;
}

if (hsv == CUDT::HS_VERSION_UDT4)
{
// The old HSv4 way: extract just one value and put it under peer.
Expand Down Expand Up @@ -2968,8 +2981,10 @@ bool CUDT::interpretSrtHandshake(const CHandShake& hs,
// (nothing to be responded for HSRSP, unless there was some kinda problem)
if (rescmd != SRT_CMD_NONE)
{
// Just formally; the current code doesn't seem to return anything else.
m_RejectReason = SRT_REJ_ROGUE;
// Just formally; the current code doesn't seem to return anything else
// (unless it's already set)
if (m_RejectReason == SRT_REJ_UNKNOWN)
m_RejectReason = SRT_REJ_ROGUE;
LOGC(cnlog.Error,
log << "interpretSrtHandshake: process HSRSP returned unexpected value " << rescmd);
return false;
Expand Down
16 changes: 16 additions & 0 deletions testing/testmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,22 @@ void SrtCommon::InitParameters(string host, string path, map<string,string> par)
par.erase("groupconfig");
}

// Fix Minversion, if specified as string
if (par.count("minversion"))
{
string v = par["minversion"];
if (v.find('.') != string::npos)
{
int version = SrtParseVersion(v.c_str());
if (version == 0)
{
throw std::runtime_error(Sprint("Value for 'minversion' doesn't specify a valid version: ", v));
}
par["minversion"] = Sprint(version);
Verb() << "\tFIXED: minversion = 0x" << std::hex << std::setfill('0') << std::setw(8) << version << std::dec;
}
}

// Assign the others here.
m_options = par;
m_options["mode"] = m_mode;
Expand Down

0 comments on commit ca79ad9

Please sign in to comment.