Skip to content

Commit

Permalink
[core] Fixed: properly handle strings with NULL characters inside (Ha…
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored Oct 16, 2023
1 parent 32d8382 commit eb80f92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,21 @@ bool srt::CUDT::interpretSrtHandshake(const CHandShake& hs,
// Un-swap on big endian machines
ItoHLA((uint32_t *)target, (uint32_t *)target, blocklen);

m_config.sStreamName.set(target, strlen(target));
// Determine the length by dropping all but one of terminal NUL characters.

size_t targetlen = bytelen;
for (size_t pos = bytelen - 1; pos != 0; --pos)
{
if (target[pos])
{
// Found the first non-NUL character backwards
// So the length is pos+1
targetlen = pos + 1;
break;
}
}

m_config.sStreamName.set(target, targetlen);
HLOGC(cnlog.Debug,
log << CONID() << "CONNECTOR'S REQUESTED SID [" << m_config.sStreamName.c_str()
<< "] (bytelen=" << bytelen << " blocklen=" << blocklen << ")");
Expand Down
2 changes: 1 addition & 1 deletion srtcore/socketconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class StringStorage

std::string str() const
{
return len == 0 ? std::string() : std::string(stor);
return len == 0 ? std::string() : std::string(stor, len);
}

const char* c_str() const
Expand Down

0 comments on commit eb80f92

Please sign in to comment.