Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add check for overflow in queue size calculation in RTOS compatibility layer. #339

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions utility/rtos_compatibility_layers/FreeRTOS/tx_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
/* start flag, corrected stack */
/* allocation size, */
/* resulting in version 6.1.12 */
/* 12-31-2023 Xiuwen Cai Modified comment(s), and */
/* added check for overflow in */
/* queue size calculation, */
/* resulting in version 6.4.0 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -1526,6 +1530,13 @@ QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize)
}
#endif

if ((uxQueueLength > (SIZE_MAX / uxItemSize)) ||
(uxQueueLength > (ULONG_MAX / uxItemSize))) {

/* Integer overflow in queue size */
return NULL;
}

p_queue = txfr_malloc(sizeof(txfr_queue_t));
if(p_queue == NULL) {
return NULL;
Expand Down Expand Up @@ -2692,6 +2703,13 @@ QueueSetHandle_t xQueueCreateSet(const UBaseType_t uxEventQueueLength)
}
#endif

if ((uxEventQueueLength > (SIZE_MAX / sizeof(void *))) ||
(uxEventQueueLength > (ULONG_MAX / sizeof(void *)))) {

/* Integer overflow in queue size */
return NULL;
}

p_set = txfr_malloc(sizeof(txfr_queueset_t));
if(p_set == NULL) {
return NULL;
Expand Down