Skip to content

Commit

Permalink
[core] Fix CUDTGroup::getOpt(..): check value length in group config …
Browse files Browse the repository at this point in the history
…storage.

The storage could have empty strings, and dereferencing the first element must not happen.
  • Loading branch information
maxsharabayko committed Nov 14, 2024
1 parent a8c6b65 commit 4e81c44
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,9 @@ void CUDTGroup::getOpt(SRT_SOCKOPT optname, void* pw_optval, int& w_optlen)

// Check if the option is in the storage, which means that
// it was modified on the group.
vector<ConfigItem>::const_iterator i = find_if(m_config.begin(), m_config.end(), FOptionValue(optname));

vector<ConfigItem>::const_iterator i = find_if(m_config.begin(), m_config.end(),
FOptionValue(optname));

if (i == m_config.end())
if (i == m_config.end() || i->value.empty())
{
// Already written to the target variable.
if (is_set_on_socket)
Expand All @@ -822,15 +820,14 @@ void CUDTGroup::getOpt(SRT_SOCKOPT optname, void* pw_optval, int& w_optlen)

return;
}
// NOTE: even if is_set_on_socket, if it was also found in the group
// settings, overwrite with the value from the group.

// Found, return the value from the storage.
// Found a value set on or derived by a group. Prefer returing it over the one taken from a member socket.
// Check the size first.
if (w_optlen < int(i->value.size()))
throw CUDTException(MJ_NOTSUP, MN_XSIZE, 0);

w_optlen = (int) i->value.size();
SRT_ASSERT(!i->value.empty());
w_optlen = (int)i->value.size();
memcpy((pw_optval), &i->value[0], i->value.size());
}

Expand Down

0 comments on commit 4e81c44

Please sign in to comment.