You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a targets flash_init() returns an errror, FlashIAP::init() will catch this and set its own return code properly, however, it does not return early. As a result it will call get_page_size() and then use new to allocate a page.
This can lead to two problems:
If new allocates successfully a memory leak may occur because the user will not expect (and should not be expected) to call deinit() after a failed init.
If get_page_size() returns wrong/junk data new may be called with a very large value and cause an Out of Memory error.
Issue #2 was seen in practice while we were testing changes to our flash driver which caused it to fail on init and which therefore caused get_page_size() to return an uninitialized value.
Target(s) affected by this defect ?
All
Toolchain(s) (name and version) displaying this defect ?
All
What version of Mbed-os are you using (tag or sha) ?
Thanks for the report, could you propose a fix and send a pull request?
If we fail in init, we should not allocate anything and return an error. It would fix 1. and also 2. (we don't have there yet defined behavior but should be call deinit only on initialized flash otherwise undefined behavior - something similar to what serial already has defined: Calling any function other than ::serial_init on am uninitialized or freed serial_t.). Proper fixing for 2nd will be once we add this behavior.
Description of defect
If a targets flash_init() returns an errror, FlashIAP::init() will catch this and set its own return code properly, however, it does not return early. As a result it will call get_page_size() and then use new to allocate a page.
This can lead to two problems:
Issue #2 was seen in practice while we were testing changes to our flash driver which caused it to fail on init and which therefore caused get_page_size() to return an uninitialized value.
Target(s) affected by this defect ?
All
Toolchain(s) (name and version) displaying this defect ?
All
What version of Mbed-os are you using (tag or sha) ?
master
sha: 3d038e5
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
N/A
How is this defect reproduced ?
Modify a targets flash_init() to return failure.
The text was updated successfully, but these errors were encountered: