Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #861, compile time assert for sockaddr size #908

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/os/portable/os-impl-bsd-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ typedef union
#endif
} OS_SockAddr_Accessor_t;

/*
* Confirm that the abstract socket address buffer size (OS_SOCKADDR_MAX_LEN) is
* large enough to store any of the enabled address types. If this is true, the
* size of the above union will match OS_SOCKADDR_MAX_LEN. However, if any
* implemention-provided struct types are larger than this, the union will be
* larger, and this indicates a configuration error.
*/
CompileTimeAssert(sizeof(OS_SockAddr_Accessor_t) == OS_SOCKADDR_MAX_LEN, SockAddrSize);

/****************************************************************************************
Sockets API
***************************************************************************************/
Expand Down Expand Up @@ -200,7 +209,7 @@ int32 OS_SocketBind_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Ad
break;
}

if (addrlen == 0 || addrlen > OS_SOCKADDR_MAX_LEN)
if (addrlen == 0)
{
return OS_ERR_BAD_ADDRESS;
}
Expand Down Expand Up @@ -560,7 +569,7 @@ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain)
break;
}

if (addrlen == 0 || addrlen > OS_SOCKADDR_MAX_LEN)
if (addrlen == 0)
{
return OS_ERR_NOT_IMPLEMENTED;
}
Expand Down