Skip to content

Commit d05b9c1

Browse files
authored
Add addition overflow check for stream buffer (#226)
1 parent c7a9a01 commit d05b9c1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

stream_buffer.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,16 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
258258
* this is a quirk of the implementation that means otherwise the free
259259
* space would be reported as one byte smaller than would be logically
260260
* expected. */
261-
xBufferSizeBytes++;
262-
pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */
261+
if( xBufferSizeBytes < ( xBufferSizeBytes + 1 + sizeof( StreamBuffer_t ) ) )
262+
{
263+
xBufferSizeBytes++;
264+
pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */
265+
}
266+
else
267+
{
268+
pucAllocatedMemory = NULL;
269+
}
270+
263271

264272
if( pucAllocatedMemory != NULL )
265273
{

0 commit comments

Comments
 (0)