Skip to content

Commit 80f164c

Browse files
committed
fix possible NULL pointer dereference after call to configASSERT()
Compiling with clang static code analysis, possible NULL pointer dereference are found. Since configASSERT() can possibly return and continue "normal" operation, the code in queue.c and stream_buffer.c can be adjusted to avoid NULL pointer exceptions. Signed-off-by: Florian La Roche <[email protected]>
1 parent 0ae0715 commit 80f164c

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

queue.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,8 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
11751175

11761176
traceENTER_xQueueGenericSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken, xCopyPosition );
11771177

1178-
configASSERT( pxQueue );
1179-
configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
1180-
configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
1178+
configASSERT( ( pxQueue != NULL ) && !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
1179+
configASSERT( ( pxQueue != NULL ) && !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
11811180

11821181
/* RTOS ports that support interrupt nesting have the concept of a maximum
11831182
* system call (or maximum API call) interrupt priority. Interrupts that are
@@ -1351,16 +1350,14 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
13511350
* not (i.e. has a task with a higher priority than us been woken by this
13521351
* post). */
13531352

1354-
configASSERT( pxQueue );
1355-
13561353
/* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR()
13571354
* if the item size is not 0. */
1358-
configASSERT( pxQueue->uxItemSize == 0 );
1355+
configASSERT( ( pxQueue != NULL ) && ( pxQueue->uxItemSize == 0 ) );
13591356

13601357
/* Normally a mutex would not be given from an interrupt, especially if
13611358
* there is a mutex holder, as priority inheritance makes no sense for an
1362-
* interrupts, only tasks. */
1363-
configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->u.xSemaphore.xMutexHolder != NULL ) ) );
1359+
* interrupt, only tasks. */
1360+
configASSERT( ( pxQueue != NULL ) && !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->u.xSemaphore.xMutexHolder != NULL ) ) );
13641361

13651362
/* RTOS ports that support interrupt nesting have the concept of a maximum
13661363
* system call (or maximum API call) interrupt priority. Interrupts that are
@@ -1895,12 +1892,9 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
18951892

18961893
traceENTER_xQueuePeek( xQueue, pvBuffer, xTicksToWait );
18971894

1898-
/* Check the pointer is not NULL. */
1899-
configASSERT( ( pxQueue ) );
1900-
19011895
/* The buffer into which data is received can only be NULL if the data size
19021896
* is zero (so no data is copied into the buffer. */
1903-
configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
1897+
configASSERT( ( pxQueue != NULL ) && !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
19041898

19051899
/* Cannot block if the scheduler is suspended. */
19061900
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
@@ -2152,9 +2146,8 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
21522146

21532147
traceENTER_xQueuePeekFromISR( xQueue, pvBuffer );
21542148

2155-
configASSERT( pxQueue );
2156-
configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
2157-
configASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */
2149+
configASSERT( ( pxQueue != NULL ) && !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
2150+
configASSERT( ( pxQueue != NULL ) && ( pxQueue->uxItemSize != 0 ) ); /* Can't peek a semaphore. */
21582151

21592152
/* RTOS ports that support interrupt nesting have the concept of a maximum
21602153
* system call (or maximum API call) interrupt priority. Interrupts that are

stream_buffer.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,11 +1653,9 @@ void vStreamBufferSetStreamBufferNotificationIndex( StreamBufferHandle_t xStream
16531653

16541654
traceENTER_vStreamBufferSetStreamBufferNotificationIndex( xStreamBuffer, uxNotificationIndex );
16551655

1656-
configASSERT( pxStreamBuffer );
1657-
16581656
/* There should be no task waiting otherwise we'd never resume them. */
1659-
configASSERT( pxStreamBuffer->xTaskWaitingToReceive == NULL );
1660-
configASSERT( pxStreamBuffer->xTaskWaitingToSend == NULL );
1657+
configASSERT( ( pxStreamBuffer != NULL ) && ( pxStreamBuffer->xTaskWaitingToReceive == NULL ) );
1658+
configASSERT( ( pxStreamBuffer != NULL ) && ( pxStreamBuffer->xTaskWaitingToSend == NULL ) );
16611659

16621660
/* Check that the task notification index is valid. */
16631661
configASSERT( uxNotificationIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES );

0 commit comments

Comments
 (0)