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 realloc_array function #443

Closed
goatshriek opened this issue Sep 26, 2024 · 5 comments
Closed

add realloc_array function #443

goatshriek opened this issue Sep 26, 2024 · 5 comments
Assignees
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

Comments

@goatshriek
Copy link
Owner

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's realloc 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 named realloc_array with the following signature:

void *
realloc_array( const void *mem, size_t item_count, size_t item_size );

Once you've made this addition, swap out the usage of realloc_mem with multiplication in src/cache.c add_page and src/target/journald.c init_fields, and make sure that all tests continue to pass.

Next, refactor stumpless_add_param in src/element.c to use the new realloc_array function. You can then create a new test in test/function/element.cpp that modifies the param_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.

@goatshriek goatshriek added enhancement new features or improvements help wanted external contributations encouraged good first issue something that would be simple for a newcomer to stumpless to work on hacktoberfest labels Sep 26, 2024
@Brijeshthummar02
Copy link

i can fix this.

@m3g4d1v3r
Copy link
Contributor

Hello there!

I've created a pull request that aims to solve this issue: #472

@ansh-dulewale
Copy link

I can fix this.

@goatshriek
Copy link
Owner Author

Pull #472 already addresses this and is near completion; it would be better to find a different issue to work on.

@goatshriek
Copy link
Owner Author

Resolved in #472.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants