Skip to content

Commit

Permalink
Merge pull request #14408 from LDong-Arm/malloc_wrapper_fix-5.15
Browse files Browse the repository at this point in the history
Add integer overflow check to the malloc wrappers
  • Loading branch information
adbridge authored Mar 22, 2021
2 parents 878a32c + 151ebfc commit 52eedfd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions platform/source/mbed_alloc_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
#endif
#ifdef MBED_HEAP_STATS_ENABLED
malloc_stats_mutex->lock();
alloc_info_t *alloc_info = (alloc_info_t *)__real__malloc_r(r, size + sizeof(alloc_info_t));
alloc_info_t *alloc_info = NULL;
if (size <= SIZE_MAX - sizeof(alloc_info_t)) {
alloc_info = (alloc_info_t *)__real__malloc_r(r, size + sizeof(alloc_info_t));
}
if (alloc_info != NULL) {
alloc_info->size = size;
alloc_info->signature = MBED_HEAP_STATS_SIGNATURE;
Expand Down Expand Up @@ -292,7 +295,10 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
#endif
#ifdef MBED_HEAP_STATS_ENABLED
malloc_stats_mutex->lock();
alloc_info_t *alloc_info = (alloc_info_t *)SUPER_MALLOC(size + sizeof(alloc_info_t));
alloc_info_t *alloc_info = NULL;
if (size <= SIZE_MAX - sizeof(alloc_info_t)) {
alloc_info = (alloc_info_t *)SUPER_MALLOC(size + sizeof(alloc_info_t));
}
if (alloc_info != NULL) {
alloc_info->size = size;
alloc_info->signature = MBED_HEAP_STATS_SIGNATURE;
Expand Down

0 comments on commit 52eedfd

Please sign in to comment.