Perform null-checks when assigning initial value of heap allocations #513
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, we operated in a model where the amount of heap memory was infinite.
For the first time (to the best of my knowledge), a piece of code started leveraging the "partial" allocation functions in the Low* libraries, here: hacl-star/hacl-star#1007. Partial allocation functions (also known as fallible) may return NULL, and the user must check that the result is non-null before doing anything with it.
This NULL-check was defeated by the fact that the initial value for the heap allocation (as provided in the Low* model) had to be compiled to an assignment (in C) that operates after the malloc but before the user got a chance to check for NULL...
The fix is simply to always guard such assignments (for the initial value to be stored in the heap allocation) to be behind null-checks.
CC @tahina-pro