Skip to content

Unreasonable Size Argument - OS_CreateSocketName static analysis warning #817

@skliper

Description

@skliper

Is your feature request related to a problem? Please describe.
Static analysis warns when using sizeof(sock->stream_name) in OS_strnlen check and later math OS_MAX_API_NAME - len passed to snprintf which out of context could then be a negative number (but isn't because OS_SocketAddrToString_Impl limits to OS_MAX_API_NAME, so this is a false positive):

if (OS_SocketAddrToString_Impl(sock->stream_name, OS_MAX_API_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);
}
sock->stream_name[OS_MAX_API_NAME - 1] = 0;

Describe the solution you'd like
Truncating the port while fully adding the parent name or possibly even truncating both seems like it could be confusing. Just truncate at the end.

Describe alternatives you've considered
Could use OS_MAX_API_NAME to limit len in first check, but seems like overkill since the size is OS_MAX_PATH_LEN.

Additional context
Static analysis warning

Requester Info
Jacob Hageman - NASA/GSFC

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions