add realloc_array function #443
Labels
enhancement
new features or improvements
good first issue
something that would be simple for a newcomer to stumpless to work on
help wanted
external contributations encouraged
Stumpless includes wrappers for memory allocation to allow a customized memory allocator to be used. One of these is
realloc_mem
, which calls the underlying allocator'srealloc
routine.As outlined in #440, there are situations where a multiplication is done to get the new size. For the same reasons outlined in that issue, it would also be helpful to add a
realloc
wrapper that does overflow checks.General Approach
There are a few details left out of the following approach, for you to fill in as you encounter them. If you find you need help, please ask here or on the project gitter and someone can help you get past the stumbling block.
First, review #440 and understand the solution proposed there; this issue is very similar. If you solved the
alloc_array
issue yourself, please leave this one for a new contributor. This is a "good first issue", and as such the learning experience is an essential component.Add a new function to
src/memory.c
namedrealloc_array
with the following signature:Once you've made this addition, swap out the usage of
realloc_mem
with multiplication insrc/cache.c
add_page
andsrc/target/journald.c
init_fields
, and make sure that all tests continue to pass.Next, refactor
stumpless_add_param
insrc/element.c
to use the newrealloc_array
function. You can then create a new test intest/function/element.cpp
that modifies theparam_count
of the element structure to be sufficiently high (SIZE_MAX
perhaps?) to cause an overflow and subsequent memory allocation failure to test your detection logic.The text was updated successfully, but these errors were encountered: