From df0ec74fc22df19591c07fab5f93cd671aa9d71a Mon Sep 17 00:00:00 2001 From: yuhzheng Date: Wed, 4 Dec 2019 07:52:49 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2759 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../Demo_IP_Protocols/FTP/FreeRTOS_FTP_server.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/FreeRTOS-Plus/Demo/Common/Demo_IP_Protocols/FTP/FreeRTOS_FTP_server.c b/FreeRTOS-Plus/Demo/Common/Demo_IP_Protocols/FTP/FreeRTOS_FTP_server.c index a2a6ba155..2d0c9197e 100644 --- a/FreeRTOS-Plus/Demo/Common/Demo_IP_Protocols/FTP/FreeRTOS_FTP_server.c +++ b/FreeRTOS-Plus/Demo/Common/Demo_IP_Protocols/FTP/FreeRTOS_FTP_server.c @@ -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 ) { -- 2.39.5