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

fix: possible memory confusion in unsafe slice cast #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jlauinger
Copy link

I found an incorrect cast from []byte to string in models/inline_strconv_parse.go. The problem is that when reflect.StringHeader is created as a composite literal (instead of deriving it from an actual slice by cast), then the Go garbage collector will not treat its Data field as a reference. If the GC runs just between creating the StringHeader and casting it into the final, real string, then the underlying data might have been collected already, effectively making the returned string a dangling pointer.

This has a low probability to occur, but projects that import this library might still use it in a code path that gets executed a lot, thus increasing the probability to happen. Depending on the memory layout at the time of the GC run, this could potentially create an information leak vulnerability.

This PR changes the function to create the reflect.StringHeader from an actual slice by first instantiating the return value.

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.

1 participant