Skip to content

test: add tests for zero sized realloc(3) #255

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cgzones
Copy link
Contributor

@cgzones cgzones commented Apr 5, 2025

C23 declared calling realloc(3) with a non-NULL pointer and zero size Undefined behavior.
Check that hardened_malloc handles that case sanely by free'ing the old pointer and returning a special pointer, like malloc(3) called with size zero.

@thestinger
Copy link
Member

This will break real world applications and isn't actually memory corruption, resulting in reduced security from not being able to use those applications from hardened_malloc.

@thestinger
Copy link
Member

The safest way to handle this is the way it already does: treating it the same way as malloc(0) by resizing to a 0 size allocation, which with hardened_malloc points to PROT_NONE memory with a unique address meeting the minimum alignment requirements for malloc despite it having a usable size of 0.

C23 declared calling realloc(3) with a non-NULL pointer and zero size
Undefined behavior.
Check that hardened_malloc handles that case sanely by free'ing the old
pointer and returning a special pointer, like `malloc(3)` called with
size zero.
@cgzones
Copy link
Contributor Author

cgzones commented Apr 5, 2025

Dropped the change in behavior, and added some additional test cases.

@cgzones cgzones changed the title Abort on C23 UB zero sized realloc test: add tests for zero sized realloc(3) May 30, 2025
@cgzones cgzones marked this pull request as ready for review May 30, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants