Skip to content

Commit

Permalink
Merge pull request #818 from skliper/fix817-unreasonable_size
Browse files Browse the repository at this point in the history
Fix #817, Simplify name truncation in OS_CreateSocketName
  • Loading branch information
astrogeco authored Feb 24, 2021
2 parents 3a29906 + 9350ee8 commit 9a4536b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/os/shared/src/osapi-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,21 @@ void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Ad

sock = OS_OBJECT_TABLE_GET(OS_stream_table, *token);

if (OS_SocketAddrToString_Impl(sock->stream_name, OS_MAX_API_NAME, Addr) != OS_SUCCESS)
if (OS_SocketAddrToString_Impl(sock->stream_name, sizeof(sock->stream_name), Addr) != OS_SUCCESS)
{
sock->stream_name[0] = 0;
}
if (OS_SocketAddrGetPort_Impl(&port, Addr) == OS_SUCCESS)
{
len = OS_strnlen(sock->stream_name, sizeof(sock->stream_name));
snprintf(&sock->stream_name[len], OS_MAX_API_NAME - len, ":%u", (unsigned int)port);
snprintf(&sock->stream_name[len], sizeof(sock->stream_name) - len, ":%u", (unsigned int)port);
}
sock->stream_name[OS_MAX_API_NAME - 1] = 0;

if (parent_name)
{
/* Append the name from the parent socket. */
len = OS_strnlen(sock->stream_name, sizeof(sock->stream_name));
snprintf(&sock->stream_name[len], sizeof(sock->stream_name) - len, "-%s", parent_name);
sock->stream_name[sizeof(sock->stream_name) - 1] = 0;
}
} /* end OS_CreateSocketName */

Expand Down

0 comments on commit 9a4536b

Please sign in to comment.