Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.4 KB

bug.md

File metadata and controls

48 lines (36 loc) · 1.4 KB

CVE-2021-31572

Add addition overflow check for stream buffer for the mostly theoretical case where you are allocating close to 4,294,967,296 bytes and the size_t rolls over.

Overflow happed when size_t xBufferSizeBytes > 2^32 - sizeof(StreamBuffer_t)

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;
}

Improve heap2 bounds checking

There was a mostly theoretical case where an overflow could occur if the size of the requested memory block is between 4,294,967,288 and 4,294,967,296 bytes.

if( xWantedSize > 0 )
{
	xWantedSize += heapSTRUCT_SIZE;
// ...
if( ( xWantedSize > 0 ) && 
   ( ( xWantedSize + heapSTRUCT_SIZE ) >  xWantedSize ) ) /* Overflow check */
{
    xWantedSize += heapSTRUCT_SIZE;