Skip to content

Commit

Permalink
[core] Haivision#2845 Add a check in srt_setsockopt to prevent optlen…
Browse files Browse the repository at this point in the history
… = -1
  • Loading branch information
yomnes0 committed Jan 9, 2024
1 parent 88c6214 commit e3ac839
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3793,7 +3793,7 @@ int srt::CUDT::getsockopt(SRTSOCKET u, int, SRT_SOCKOPT optname, void* pw_optval

int srt::CUDT::setsockopt(SRTSOCKET u, int, SRT_SOCKOPT optname, const void* optval, int optlen)
{
if (!optval)
if (!optval || optlen < 0)
return APIError(MJ_NOTSUP, MN_INVAL, 0);

try
Expand Down
9 changes: 9 additions & 0 deletions test/test_socket_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,15 @@ TEST_F(TestSocketOptions, StreamIDWrongLen)
EXPECT_EQ(srt_getlasterror(NULL), SRT_EINVPARAM);
}

//Check if setting -1 as optlen returns an error
TEST_F(TestSocketOptions, StringOptLenInvalid)
{

string stream_id = "test123";
EXPECT_EQ(srt_setsockopt(m_caller_sock, 0, SRTO_STREAMID, stream_id.c_str(), -1), 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.
Expand Down

0 comments on commit e3ac839

Please sign in to comment.