-
Notifications
You must be signed in to change notification settings - Fork 865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Fixed incorrect setting streamid in internal config in HS (last 4 characters) #1868
[core] Fixed incorrect setting streamid in internal config in HS (last 4 characters) #1868
Conversation
A good case to extend socket option unit tests. Possible test cases:
|
Just one more note: there's no problem with two other string-type extensions, congctl and packetfilter, because they are directly assigned to |
Some unit tests. // Try to set a wrong SRTO_STREAMID.
TEST_F(TestSocketOptions, StreamIDWrongLen)
{
char buffer[648];
for (size_t i = 0; i < sizeof buffer; ++i)
buffer[i] = 'a' + i % 25;
EXPECT_EQ(srt_setsockopt(m_caller_sock, 0, SRTO_STREAMID, buffer, 513), SRT_ERROR);
EXPECT_EQ(srt_getlasterror(NULL), SRT_EINVPARAM);
}
// Try to set/get a 13-character string in SRTO_STREAMID.
// This tests checks that the StreamID is set to the correct size
// while it is transmitted as 16 characters in the Stream ID HS extension.
TEST_F(TestSocketOptions, StreamIDLen13)
{
string stream_id_13 = "something1234";
EXPECT_EQ(srt_setsockopt(m_caller_sock, 0, SRTO_STREAMID, stream_id_13.c_str(), stream_id_13.size()), SRT_SUCCESS);
char buffer[648];
int buffer_len = sizeof buffer;
EXPECT_EQ(srt_getsockopt(m_caller_sock, 0, SRTO_STREAMID, &buffer, &buffer_len), SRT_SUCCESS);
StartListener();
const SRTSOCKET accepted_sock = EstablishConnection();
// Check accepted socket inherits values
for (SRTSOCKET sock : { accepted_sock })
{
for (size_t i = 0; i < sizeof buffer; ++i)
buffer[i] = 'a';
buffer_len = (int)(sizeof buffer);
EXPECT_EQ(srt_getsockopt(sock, 0, SRTO_STREAMID, &buffer, &buffer_len), SRT_SUCCESS);
EXPECT_EQ(buffer_len, 13);
}
ASSERT_NE(srt_close(accepted_sock), SRT_ERROR);
} |
Setting
TODO
TEST_F(TestSocketOptions, StreamIDLenListener)
{
string stream_id_13 = "something1234";
EXPECT_EQ(srt_setsockopt(m_listen_sock, 0, SRTO_STREAMID, stream_id_13.c_str(), stream_id_13.size()), SRT_SUCCESS);
char buffer[648];
int buffer_len = sizeof buffer;
EXPECT_EQ(srt_getsockopt(m_listen_sock, 0, SRTO_STREAMID, &buffer, &buffer_len), SRT_SUCCESS);
StartListener();
const SRTSOCKET accepted_sock = EstablishConnection();
// Check accepted socket inherits values
for (SRTSOCKET sock : { m_caller_sock, accepted_sock })
{
for (size_t i = 0; i < sizeof buffer; ++i)
buffer[i] = 'a';
buffer_len = (int)(sizeof buffer);
EXPECT_EQ(srt_getsockopt(sock, 0, SRTO_STREAMID, &buffer, &buffer_len), SRT_SUCCESS);
EXPECT_EQ(buffer_len, 0) << (sock == accepted_sock ? "ACCEPTED" : "LISTENER");
}
ASSERT_NE(srt_close(accepted_sock), SRT_ERROR);
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minoir edit
Co-authored-by: stevomatthews <smatthews@haivision.com>
The problem:
The STREAMID (like all other string-type extensions) if it was set the length 509-512 (which is still legal), was rejected during setting of the config string because the length was taken as 512.
The string is passed in 4-byte chunks, which is then padded with zeros if the number of characters is not aligned to 4. The length to set the string was however calculated as the size of the extension data (which are 128 for the given sizes) multiplied by size of the field (4), which resulted to always 512, which exceeds the allowed size.
As the size of the actual string should be up to the first 0, the length should be taken directly by
strlen
because the length calculated out ofblocklen
may include the padding zeros, which makes the size wrong.Additionally fixed bug in StringStorage: the condition for too big length is wrong.