-
Notifications
You must be signed in to change notification settings - Fork 42
Add overflow tests #587
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 overflow tests #587
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,11 @@ umf_ba_linear_pool_t *umf_ba_linear_create(size_t pool_size) { | |
pool_size = MINIMUM_LINEAR_POOL_SIZE; | ||
} | ||
|
||
pool_size = ALIGN_UP(pool_size, ba_os_get_page_size()); | ||
pool_size = ALIGN_UP_SAFE(pool_size, ba_os_get_page_size()); | ||
if (pool_size == 0) { | ||
LOG_ERR("pool_size page alignment overflow"); | ||
return NULL; | ||
} | ||
|
||
umf_ba_linear_pool_t *pool = (umf_ba_linear_pool_t *)ba_os_alloc(pool_size); | ||
if (!pool) { | ||
|
@@ -122,15 +126,24 @@ void *umf_ba_linear_alloc(umf_ba_linear_pool_t *pool, size_t size) { | |
if (size == 0) { | ||
return NULL; | ||
} | ||
size_t aligned_size = ALIGN_UP(size, MEMORY_ALIGNMENT); | ||
size_t aligned_size = ALIGN_UP_SAFE(size, MEMORY_ALIGNMENT); | ||
if (aligned_size == 0) { | ||
LOG_ERR("size alignment overflow"); | ||
return NULL; | ||
} | ||
utils_mutex_lock(&pool->metadata.lock); | ||
if (pool->metadata.size_left < aligned_size) { | ||
size_t pool_size = MINIMUM_LINEAR_POOL_SIZE; | ||
size_t usable_size = | ||
pool_size - offsetof(umf_ba_next_linear_pool_t, data); | ||
if (usable_size < aligned_size) { | ||
pool_size += aligned_size - usable_size; | ||
pool_size = ALIGN_UP(pool_size, ba_os_get_page_size()); | ||
pool_size = ALIGN_UP_SAFE(pool_size, ba_os_get_page_size()); | ||
if (pool_size == 0) { | ||
utils_mutex_unlock(&pool->metadata.lock); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the Helgrind log, I believe the problem is here. Are you sure it should be done here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I have to release the mutex before returning from this function. |
||
LOG_ERR("pool_size page alignment overflow"); | ||
return NULL; | ||
} | ||
} | ||
|
||
assert(pool_size - offsetof(umf_ba_next_linear_pool_t, data) >= | ||
|
Uh oh!
There was an error while loading. Please reload this page.