Check socket binding result before doing anything with socket. (This is to address ARG findings.) Breaking the single return rule here, due to precedent violation at line 1039 and 1144.

prvTransferConnect() now returns:
- pdTRUE: everything's good. pdTRUE = 1.
- -pdFREERTOS_ERRNO_ENOMEM: FreeRTOS_socket() failed. -pdFREERTOS_ERRNO_ENOMEM = -12.
- -pdFREERTOS_ERRNO_EINVAL || -pdFREERTOS_ERRNO_ECANCELED: FreeRTOS_bind() failed. Negative values.

Thus, at line 569 and line 617, needs to check != pdTRUE instead of == pdFALSE.

This commit is done on behalf of Alfred.
This commit is contained in:
Yuhui.Zheng 2019-12-04 07:52:49 +00:00
parent 9491af1fd7
commit 1deeb6dd84

View File

@ -566,7 +566,7 @@ BaseType_t xResult = 0;
case ECMD_PASV: /* Enter passive mode. */
/* Connect passive: Server will listen() and wait for a connection.
Start up a new data connection with 'xDoListen' set to true. */
if( prvTransferConnect( pxClient, pdTRUE ) == pdFALSE )
if( prvTransferConnect( pxClient, pdTRUE ) != pdTRUE )
{
pcMyReply = REPL_502;
}
@ -614,7 +614,7 @@ BaseType_t xResult = 0;
{
pcMyReply = REPL_501;
}
else if( prvTransferConnect( pxClient, pdFALSE ) == pdFALSE )
else if( prvTransferConnect( pxClient, pdFALSE ) != pdTRUE )
{
/* Call prvTransferConnect() with 'xDoListen' = false for an
active connect(). */
@ -850,7 +850,13 @@ BaseType_t xResult;
xAddress.sin_addr = FreeRTOS_GetIPAddress( ); /* Single NIC, currently not used */
xAddress.sin_port = FreeRTOS_htons( 0 ); /* Bind to any available port number */
FreeRTOS_bind( xSocket, &xAddress, sizeof( xAddress ) );
BaseType_t xBindResult;
xBindResult = FreeRTOS_bind( xSocket, &xAddress, sizeof( xAddress ) );
if ( xBindResult != 0 )
{
FreeRTOS_printf( ( "FreeRTOS_bind() failed\n" ) );
return xBindResult;
}
#if( ipconfigFTP_TX_BUFSIZE > 0 )
{