Skip to content

fix(state): initialize maps omitted from the persisted state - #1117

Open
Vivek1106-04 wants to merge 1 commit into
canonical:masterfrom
Vivek1106-04:fix/state-read-omitted-maps
Open

Vivek1106-04 wants to merge 1 commit into
canonical:masterfrom
Vivek1106-04:fix/state-read-omitted-maps

Conversation

@Vivek1106-04

Copy link
Copy Markdown

Fixes #1017.

State.UnmarshalJSON assigned the decoded Data, Changes and Tasks maps directly, so a valid state document that omits them (for example {}) left those maps nil. A later Set, NewTask or NewChange then panicked with assignment to entry in nil map.

This initializes any of the three maps that are nil after decoding. Notices were already safe, since unflattenNotices always makes a new map. The fix is in UnmarshalJSON rather than ReadState, so any path that decodes a State gets it.

Testing

  • Added TestReadStateOmittedFields: reads {} and then calls Set, NewTask, NewChange and AddTask. It panicked before the fix and passes after.
  • go test -race ./internals/overlord/state/ passes.

ReadState on a state document that omits data, changes or tasks (for
example "{}") left those maps nil, so a later Set, NewTask or NewChange
panicked with an assignment to entry in nil map.

Fixes canonical#1017

This branch has not been deployed

No deployments
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 this pull request may close these issues.

ReadState can return nil persisted maps for omitted fields

1 participant