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

net: IP.To4 retains reference to IPv6 IP #10104

Closed
anacrolix opened this issue Mar 8, 2015 · 2 comments
Closed

net: IP.To4 retains reference to IPv6 IP #10104

anacrolix opened this issue Mar 8, 2015 · 2 comments

Comments

@anacrolix
Copy link
Contributor

Calling .To4 on an IPv6 IP, returns a slice of the IPv4 part of the address. Elsewhere new buffers are allocated instead, and it's natural to assume this is the case for To4 as well. User code can proceed assuming it now owns the contents of net.IP which is not correct.

To4 converts the IPv4 address ip to a 4-byte representation. If ip is not an IPv4 address, To4 returns nil. There is no guarantee the returned IP is freshly allocated.

?

@minux
Copy link
Member

minux commented Mar 8, 2015 via email

@rsc
Copy link
Contributor

rsc commented Apr 10, 2015

This was intentional. You probably shouldn't modify IP addresses' slice data once created.

@rsc rsc closed this as completed Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants