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

Make FindFabricByIndex const to avoid unexpected/invalid mutations of FabricTable #19929

Closed
tcarmelveilleux opened this issue Jun 24, 2022 · 0 comments · Fixed by #20088
Closed
Assignees

Comments

@tcarmelveilleux
Copy link
Contributor

Problem

It is now forbidden to mutate FabricInfo entries directly without going via FabricTable APIs.

However, it was non-const long enough that many callsites only use const getters, but get a non-const pointer!

We need to fix this

Proposed Solution

  • Make the non-const version called "GetMutableFabricByIndex". This is for every callsite in FabricTable.cpp, and ONLY THERE. Make it private.
  • Make FindFabricByIndex return const FabricInfo * and be const.
  • Fix all callsites that now break due to constness
@tcarmelveilleux tcarmelveilleux self-assigned this Jun 24, 2022
tcarmelveilleux added a commit to tcarmelveilleux/connectedhomeip that referenced this issue Jun 29, 2022
- Only FabricTable APIs are allowed to mutate FabricInfo entries
  due to the requirements of fail-safe shadow data handling
- Previous PRs made sure none of the mutators were used outside
  of FabricTable, but `FindFabricByIndex` remained a non-const
  getter due to how much code was using it.

Fixes project-chip#19929

This PR:

- Renames the mutable `FabricInfo *` getter as `GetMutableFabricByIndex()`
  and makes it private to FabricTable.
- Adds `const` qualifier to every other usage of FindFabricByIndex in the SDK.

Testing done:

- All unit tests pass
- Cert tests still pass
- Still compiles
tcarmelveilleux added a commit that referenced this issue Jun 29, 2022
* Make all public FabricInfo getters const

- Only FabricTable APIs are allowed to mutate FabricInfo entries
  due to the requirements of fail-safe shadow data handling
- Previous PRs made sure none of the mutators were used outside
  of FabricTable, but `FindFabricByIndex` remained a non-const
  getter due to how much code was using it.

Fixes #19929

This PR:

- Renames the mutable `FabricInfo *` getter as `GetMutableFabricByIndex()`
  and makes it private to FabricTable.
- Adds `const` qualifier to every other usage of FindFabricByIndex in the SDK.

Testing done:

- All unit tests pass
- Cert tests still pass
- Still compiles

* Fix CI on Shell

* Fix one const in ESP32 ShellCommands.h
woody-apple pushed a commit to woody-apple/connectedhomeip that referenced this issue Jun 29, 2022
* Make all public FabricInfo getters const

- Only FabricTable APIs are allowed to mutate FabricInfo entries
  due to the requirements of fail-safe shadow data handling
- Previous PRs made sure none of the mutators were used outside
  of FabricTable, but `FindFabricByIndex` remained a non-const
  getter due to how much code was using it.

Fixes project-chip#19929

This PR:

- Renames the mutable `FabricInfo *` getter as `GetMutableFabricByIndex()`
  and makes it private to FabricTable.
- Adds `const` qualifier to every other usage of FindFabricByIndex in the SDK.

Testing done:

- All unit tests pass
- Cert tests still pass
- Still compiles

* Fix CI on Shell

* Fix one const in ESP32 ShellCommands.h
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 a pull request may close this issue.

1 participant