Skip to content

Commit

Permalink
Merge pull request nasa#908 from jphickey/fix-861-sockaddr-size-check
Browse files Browse the repository at this point in the history
Fix nasa#861, compile time assert for sockaddr size
  • Loading branch information
astrogeco committed Mar 22, 2021
2 parents c29a2f4 + 87c9cf2 commit a54f95f
Showing 1 changed file with 11 additions and 2 deletions.
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 @@ -192,7 +201,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 @@ -570,7 +579,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

0 comments on commit a54f95f

Please sign in to comment.