Skip to content

Commit

Permalink
Fix nasa#817, Simplify name truncation in OS_CreateSocketName
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Feb 17, 2021
1 parent ff4f523 commit 9350ee8
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 9350ee8

Please sign in to comment.