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

tflog+tfsdklog: Prevent slice/map leaks when setting LoggerOpts #132

Merged
merged 3 commits into from
Feb 8, 2023

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Feb 7, 2023

Reference #126
Closes #131

Since the LoggerOpts struct contains slice and map fields, it is important to ensure any modifications occur on copies of those slices and maps, otherwise the memory reference can wind up being shared. Consumers should always be able to create a new context.Context without worrying about shared data.

This change introduces a Copy() method for LoggerOpts and implements it for option modifier functions which adjust a map or slice.

Reference: #126
Reference: #131

Since the `LoggerOpts` struct contains slice and map fields, it is important to ensure any modifications occur on copies of those slices and maps, otherwise the memory reference can wind up being shared. Consumers should always be able to create a new `context.Context` without worrying about shared data.

This change introduces a `Copy()` method for `LoggerOpts` and implements it for option modifier functions which adjust a map or slice.
@bflad bflad added the bug Something isn't working label Feb 7, 2023
@bflad bflad added this to the v0.8.0 milestone Feb 7, 2023
@bflad bflad requested a review from a team as a code owner February 7, 2023 21:54
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻

Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

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

LGTM 👍


tflog.Trace(originalCtx, "original should be masked")
tflog.Trace(originalCtx, "new should be preserved")
tflog.Trace(newCtx, "new should be masked")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth using different log levels for originalCtx and newCtx in order to be able to differentiate between them in the expectedOutput?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing -- will adjust


tflog.Trace(originalCtx, "original should be masked")
tflog.Trace(originalCtx, "new should be preserved")
tflog.Trace(newCtx, "new should be masked")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth using different log levels for originalCtx and newCtx in order to be able to differentiate between them in the expectedOutput?

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fields set with SetField leak
3 participants