Skip to content

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

Merged
bflad merged 3 commits intomainfrom
bflad/loggeropts-copy
Feb 8, 2023
Merged

tflog+tfsdklog: Prevent slice/map leaks when setting LoggerOpts#132
bflad merged 3 commits intomainfrom
bflad/loggeropts-copy

Conversation

@bflad
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 👍

Comment thread tflog/provider_test.go Outdated

tflog.Trace(originalCtx, "original should be masked")
tflog.Trace(originalCtx, "new should be preserved")
tflog.Trace(newCtx, "new should be masked")
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread tflog/provider_test.go Outdated

tflog.Trace(originalCtx, "original should be masked")
tflog.Trace(originalCtx, "new should be preserved")
tflog.Trace(newCtx, "new should be masked")
Copy link
Copy Markdown
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
Copy Markdown

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