Skip to content

Commit 91163a8

Browse files
projectgusdonghengqaz
authored andcommitted
freertos: Add addition overflow check for stream buffer
Patch from upstream commit d05b9c123f2bf9090bce386a244fc934ae44db5b
1 parent b54fb1b commit 91163a8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

components/freertos/freertos/stream_buffer.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,15 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
242242
this is a quirk of the implementation that means otherwise the free
243243
space would be reported as one byte smaller than would be logically
244244
expected. */
245-
xBufferSizeBytes++;
246-
pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */
245+
if( xBufferSizeBytes < ( xBufferSizeBytes + 1 + sizeof( StreamBuffer_t ) ) )
246+
{
247+
xBufferSizeBytes++;
248+
pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */
249+
}
250+
else
251+
{
252+
pucAllocatedMemory = NULL;
253+
}
247254

248255
if( pucAllocatedMemory != NULL )
249256
{

0 commit comments

Comments
 (0)