Skip to content

SecureStore: Add member initializers for inc_handle_t #11810

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

Merged
merged 1 commit into from
Nov 7, 2019

Conversation

kyle-cypress
Copy link

Description (required)

_inc_set_handle is new'd in SecureStore::init(), then its members are referenced in various functions without being explicitly initialized first. These pre-existing values can confuse the SecureStore's internal state and cause various undesired behaviors.

Note: At least on the ARM GCC versions that I've tested with (6.3.1 and 7.2.1), the default initialization is also achieved by using new inc_set_handle_t(); instead of new inc_set_handle_t; (note the added parentheses). I chose to add explicit initializers instead because a.) it is hard to tell whether this behavior is guaranteed by spec or just how GCC happens to be implemented and b.) the explicit initializers make it more clear what is going on (and are not prone to failure if a future change forgets to use parentheses with new).

Summary of change (What the change is for and why)

Fix use of uninitialized memory contents in SecureStore.

Documentation (Details of any document updates required)

Pull request type (required)

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results (required)

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

A full Greentea test log will be uploaded soon (probably tomorrow).


Reviewers (optional)

@ARMMbed/team-cypress


Release Notes (required for feature/major PRs)

Summary of changes
Impact of changes
Migration actions required

_inc_set_handle is new'd in SecureStore::init(), then its members are
referenced in various functions without being explicitly initialized
first. These pre-existing values can confuse the SecureStore's internal
state and cause various undesired behavior.
@ciarmcom ciarmcom requested review from a team November 5, 2019 02:00
@ciarmcom
Copy link
Member

ciarmcom commented Nov 5, 2019

@kyle-cypress, thank you for your changes.
@ARMmbed/mbed-os-storage @ARMmbed/mbed-os-maintainers please review.

@kjbracey
Copy link
Contributor

kjbracey commented Nov 5, 2019

On the language point, new inc_set_handle_t() is guaranteed to work. Why is complicated. As of C++11, that's called "value initialisation" and the logic is:

  • If there is a user-provided default constructor, it calls that (same as new inc_set_handle_t), and then it's up to that constructor to initialise stuff properly. If it doesn't, it's that constructor's fault.
  • If there is no user-provided default constructor, it zero-initialises (covering any plain members), then default-initialises (covering any class members).

Anyway, I'm happy with the default member initialisers as you've done it.

@kyle-cypress
Copy link
Author

Greentea test results: greentea.txt
The hal-sleep and hal-sleep_manager are a known failure on Cypress targets.

Note: These test were run with the changes from #11531 applied, because the kvstore tests do not run at all on Cypress targets without that PR. This PR is NOT dependent on #11531.

Copy link
Contributor

@VeijoPesonen VeijoPesonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 6, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Nov 6, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

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

Successfully merging this pull request may close these issues.

6 participants