mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-21 22:11:57 -04:00
Improvement to O.F. protections (#75)
* Added protection for xQueueGenericCreate * prevent eventual invalid state change from int8 overflow * Append period at end of comment. To be consistent with file. * check operand, not destination * parantheses -- to not show assumptive precendence * Per request, less dependence on stdint by defining and checking against queueINT8_MAX instead
This commit is contained in:
parent
b47ca712d8
commit
4a61f9ff7e
12
queue.c
12
queue.c
|
@ -51,6 +51,7 @@ correct privileged Vs unprivileged linkage and placement. */
|
||||||
/* Constants used with the cRxLock and cTxLock structure members. */
|
/* Constants used with the cRxLock and cTxLock structure members. */
|
||||||
#define queueUNLOCKED ( ( int8_t ) -1 )
|
#define queueUNLOCKED ( ( int8_t ) -1 )
|
||||||
#define queueLOCKED_UNMODIFIED ( ( int8_t ) 0 )
|
#define queueLOCKED_UNMODIFIED ( ( int8_t ) 0 )
|
||||||
|
#define queueINT8_MAX ( ( int8_t ) 127 )
|
||||||
|
|
||||||
/* When the Queue_t structure is used to represent a base queue its pcHead and
|
/* When the Queue_t structure is used to represent a base queue its pcHead and
|
||||||
pcTail members are used as pointers into the queue storage area. When the
|
pcTail members are used as pointers into the queue storage area. When the
|
||||||
|
@ -378,6 +379,9 @@ Queue_t * const pxQueue = xQueue;
|
||||||
zero in the case the queue is used as a semaphore. */
|
zero in the case the queue is used as a semaphore. */
|
||||||
xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
|
xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
|
||||||
|
|
||||||
|
/* Check for multiplication overflow. */
|
||||||
|
configASSERT( ( uxItemSize == 0 ) || ( uxQueueLength == ( xQueueSizeInBytes / uxItemSize ) ) );
|
||||||
|
|
||||||
/* Allocate the queue and storage area. Justification for MISRA
|
/* Allocate the queue and storage area. Justification for MISRA
|
||||||
deviation as follows: pvPortMalloc() always ensures returned memory
|
deviation as follows: pvPortMalloc() always ensures returned memory
|
||||||
blocks are aligned per the requirements of the MCU stack. In this case
|
blocks are aligned per the requirements of the MCU stack. In this case
|
||||||
|
@ -1092,6 +1096,8 @@ Queue_t * const pxQueue = xQueue;
|
||||||
{
|
{
|
||||||
/* Increment the lock count so the task that unlocks the queue
|
/* Increment the lock count so the task that unlocks the queue
|
||||||
knows that data was posted while it was locked. */
|
knows that data was posted while it was locked. */
|
||||||
|
configASSERT( cTxLock != queueINT8_MAX);
|
||||||
|
|
||||||
pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );
|
pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1257,6 +1263,8 @@ Queue_t * const pxQueue = xQueue;
|
||||||
{
|
{
|
||||||
/* Increment the lock count so the task that unlocks the queue
|
/* Increment the lock count so the task that unlocks the queue
|
||||||
knows that data was posted while it was locked. */
|
knows that data was posted while it was locked. */
|
||||||
|
configASSERT( cTxLock != queueINT8_MAX);
|
||||||
|
|
||||||
pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );
|
pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1856,6 +1864,8 @@ Queue_t * const pxQueue = xQueue;
|
||||||
{
|
{
|
||||||
/* Increment the lock count so the task that unlocks the queue
|
/* Increment the lock count so the task that unlocks the queue
|
||||||
knows that data was removed while it was locked. */
|
knows that data was removed while it was locked. */
|
||||||
|
configASSERT( cRxLock != queueINT8_MAX);
|
||||||
|
|
||||||
pxQueue->cRxLock = ( int8_t ) ( cRxLock + 1 );
|
pxQueue->cRxLock = ( int8_t ) ( cRxLock + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2919,6 +2929,8 @@ Queue_t * const pxQueue = xQueue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
configASSERT( cTxLock != queueINT8_MAX);
|
||||||
|
|
||||||
pxQueueSetContainer->cTxLock = ( int8_t ) ( cTxLock + 1 );
|
pxQueueSetContainer->cTxLock = ( int8_t ) ( cTxLock + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue