From 0cdf98eda10400a303cc9356bb7689c1bb0c3ca1 Mon Sep 17 00:00:00 2001 From: tabudz Date: Fri, 21 Feb 2025 22:06:22 +0800 Subject: [PATCH] Add addition overflow check for stream buffer --- .../Third_Party/FreeRTOS/Source/stream_buffer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/demo/os/cube-freertos/nucleo-g070rb/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c b/demo/os/cube-freertos/nucleo-g070rb/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c index 7ad5d54..ee18ca4 100644 --- a/demo/os/cube-freertos/nucleo-g070rb/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c +++ b/demo/os/cube-freertos/nucleo-g070rb/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c @@ -254,9 +254,16 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer, this is a quirk of the implementation that means otherwise the free space would be reported as one byte smaller than would be logically expected. */ - xBufferSizeBytes++; - pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */ - + if( xBufferSizeBytes < ( xBufferSizeBytes + 1 + sizeof( StreamBuffer_t ) ) ) + { + xBufferSizeBytes++; + pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */ + } + else + { + pucAllocatedMemory = NULL; + } + if( pucAllocatedMemory != NULL ) { prvInitialiseNewStreamBuffer( ( StreamBuffer_t * ) pucAllocatedMemory, /* Structure at the start of the allocated memory. */ /*lint !e9087 Safe cast as allocated memory is aligned. */ /*lint !e826 Area is not too small and alignment is guaranteed provided malloc() behaves as expected and returns aligned buffer. */