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

Stdlib rand() in global ctor causes hard fault #6997

Closed
srickardti opened this issue May 20, 2021 · 0 comments · Fixed by #6998 or #10506
Closed

Stdlib rand() in global ctor causes hard fault #6997

srickardti opened this issue May 20, 2021 · 0 comments · Fixed by #6998 or #10506

Comments

@srickardti
Copy link
Contributor

Problem

The PR for #5389 introduced a new global object for the unencrypted message counter. This c++ object is initialized at global scope with a pseudorandom number from rand(). In this case, rand() is supplied by the newlib-nano standard library. This implementation of rand() is meant to be reentrant, so it calls the FreeRTOS function to get the reent struct. Which ends up attempting to alloc memory for the new reent struct. The system heap is not setup on the TI platform until main, causing a hard fault.

Proposed Solution

Eclipsing the stdlib implementation of rand() and srand() is the simplest change. A basic non-reentrant function will work for the PRNG assumption here. The TRNG and DRBG can be fulfilled by other sources where needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant