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

[FIXED] Make sure to use byte slice to receive proper copy #59

Merged
merged 1 commit into from Oct 23, 2023

Conversation

derekcollison
Copy link
Member

@derekcollison derekcollison commented Oct 21, 2023

Empty public key was being used.

Huge thanks for the report from @tinou98!

Signed-off-by: Derek Collison derek@nats.io

…ublic key is being used.

Signed-off-by: Derek Collison <derek@nats.io>
@coveralls
Copy link

Pull Request Test Coverage Report for Build 6598807631

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 80.115%

Totals Coverage Status
Change from base Build 6225067835: 0.4%
Covered Lines: 419
Relevant Lines: 523

💛 - Coveralls

Copy link
Member

@philpennock philpennock left a comment

Choose a reason for hiding this comment

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

I don't think this is needed. I think it's fine to apply as a comprehension change, but I think the logic before was correct.

Notably, the prior state was that the input was an array, not a slice, and that the [:] did not force a capacity limit and thus a reallocation.

https://go.dev/play/p/c3N6VcA-L1Q

See that test code, and how using y := x[:] before copying into y also updates x.

So I don't think there's a security issue here. But it's good to be clear, so approving the changes.

Copy link
Member

@aricart aricart 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
Member

@philpennock philpennock left a comment

Choose a reason for hiding this comment

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

Okay, so the actual problem is caused by missing that Go is pass-by-value and when you're passing in an array, you get a copy of the array, so the passing in of the slice over the array results in the called function getting a new slice value over the same array, and being able to modify the caller.

@philpennock
Copy link
Member

Please update the title before merge, because "Make sure to use byte slice to receive proper copy" is ... the opposite of true? You're using a byte slice so that you're not getting a copy of the underlaying data and can instead modify the original.

@derekcollison
Copy link
Member Author

The title I believe is correct, we would copy the byte array on the stack, so when we copied it into that copy, it was lost. Using the slice we do get the data correctly when we return.

@derekcollison derekcollison merged commit d2e442e into main Oct 23, 2023
6 checks passed
@derekcollison derekcollison deleted the empty branch December 28, 2023 17:35
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.

None yet

4 participants