Skip to content

Commit 1f61846

Browse files
authored
Add response buffer len check (FreeRTOS#125)
Add response buffer length check Add bufferLen is zero unit test
1 parent 4a8634e commit 1f61846

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

source/core_http_client.c

+4
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,10 @@ HTTPStatus_t HTTPClient_Send( const TransportInterface_t * pTransport,
22012201
{
22022202
LogError( ( "Parameter check failed: pResponse->pBuffer is NULL." ) );
22032203
}
2204+
else if( pResponse->bufferLen == 0U )
2205+
{
2206+
LogError( ( "Parameter check failed: pResponse->bufferLen is zero." ) );
2207+
}
22042208
else if( ( pRequestBodyBuf == NULL ) && ( reqBodyBufLen > 0U ) )
22052209
{
22062210
/* If there is no body to send we must ensure that the reqBodyBufLen is

test/unit-test/core_http_send_utest.c

+19
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,25 @@ void test_HTTPClient_Send_null_response_buffer( void )
14891489

14901490
/*-----------------------------------------------------------*/
14911491

1492+
/* Test a 0 response buffer length passed to the API. */
1493+
void test_HTTPClient_Send_zero_response_buffer_len( void )
1494+
{
1495+
HTTPStatus_t returnStatus = HTTPSuccess;
1496+
1497+
response.pBuffer = httpBuffer;
1498+
response.bufferLen = 0U;
1499+
returnStatus = HTTPClient_Send( &transportInterface,
1500+
&requestHeaders,
1501+
NULL,
1502+
0,
1503+
&response,
1504+
0 );
1505+
1506+
TEST_ASSERT_EQUAL( HTTPInvalidParameter, returnStatus );
1507+
}
1508+
1509+
/*-----------------------------------------------------------*/
1510+
14921511
/* Test when reqBodyBufLen is greater than the max value of a 32-bit integer. */
14931512
void test_HTTPClient_Send_request_body_buffer_length_gt_max( void )
14941513
{

0 commit comments

Comments
 (0)