From 9350ee81584f5589741440ee55f330ff0f764d81 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Wed, 17 Feb 2021 09:37:34 -0500 Subject: [PATCH] Fix #817, Simplify name truncation in OS_CreateSocketName --- src/os/shared/src/osapi-sockets.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/os/shared/src/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c index cdf0fded9..9068107b9 100644 --- a/src/os/shared/src/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -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 */