Fix: Potential Segfault - Validate socket handle before dereferencing
@@ -412,11 +412,6 @@ int32_t SOCKETS_Recv( Socket_t xSocket,
{
ss_ctx_t * ctx = ( ss_ctx_t * ) xSocket;
- if( ( ctx->status & SS_STATUS_CONNECTED ) != SS_STATUS_CONNECTED )
- {
- return SOCKETS_ENOTCONN;
- }
-
if( SOCKETS_INVALID_SOCKET == xSocket )
{
return SOCKETS_SOCKET_ERROR;
@@ -427,6 +422,11 @@ int32_t SOCKETS_Recv( Socket_t xSocket,
return SOCKETS_EINVAL;
}
+ if( ( ctx->status & SS_STATUS_CONNECTED ) != SS_STATUS_CONNECTED )
+ {
+ return SOCKETS_ENOTCONN;
+ }
+
ctx->recv_flag = ulFlags;
if( 0 > ctx->ip_socket )
