File tree 1 file changed +24
-1
lines changed
components/freertos/freertos
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -360,6 +360,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
360
360
Queue_t * pxNewQueue ;
361
361
size_t xQueueSizeInBytes ;
362
362
uint8_t * pucQueueStorage ;
363
+ BaseType_t overflow ;
363
364
364
365
configASSERT ( uxQueueLength > ( UBaseType_t ) 0 );
365
366
@@ -375,7 +376,29 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
375
376
xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
376
377
}
377
378
378
- pxNewQueue = ( Queue_t * ) pvPortMalloc ( sizeof ( Queue_t ) + xQueueSizeInBytes );
379
+ /* Check for multiplication overflow. */
380
+ overflow = ( uxItemSize != 0 ) && ( uxQueueLength != ( xQueueSizeInBytes / uxItemSize ) );
381
+
382
+ /* Check for addition overflow. */
383
+ overflow = overflow || ( ( sizeof ( Queue_t ) + xQueueSizeInBytes ) < xQueueSizeInBytes );
384
+
385
+ if ( overflow == (BaseType_t ) 0 )
386
+ {
387
+ /* Allocate the queue and storage area. Justification for MISRA
388
+ deviation as follows: pvPortMalloc() always ensures returned memory
389
+ blocks are aligned per the requirements of the MCU stack. In this case
390
+ pvPortMalloc() must return a pointer that is guaranteed to meet the
391
+ alignment requirements of the Queue_t structure - which in this case
392
+ is an int8_t *. Therefore, whenever the stack alignment requirements
393
+ are greater than or equal to the pointer to char requirements the cast
394
+ is safe. In other cases alignment requirements are not strict (one or
395
+ two bytes). */
396
+ pxNewQueue = ( Queue_t * ) pvPortMalloc ( sizeof ( Queue_t ) + xQueueSizeInBytes ); /*lint !e9087 !e9079 see comment above. */
397
+ }
398
+ else
399
+ {
400
+ pxNewQueue = NULL ;
401
+ }
379
402
380
403
if ( pxNewQueue != NULL )
381
404
{
You can’t perform that action at this time.
0 commit comments