Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add integer overflow check to the malloc wrappers #14407

Merged
merged 1 commit into from
Mar 11, 2021
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
10 changes: 8 additions & 2 deletions platform/source/mbed_alloc_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
#endif
#if 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 @@ -301,7 +304,10 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
#endif
#if 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