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: bad shadowing in ipsock_posix.go; unhelpful ip.String result #15052

ianlancetaylor opened this issue Mar 31, 2016 · 3 comments


None yet
3 participants
Copy link

commented Mar 31, 2016

On tip, the file net/ipsock_posix.go has these lines

        if ip = ip.To4(); ip == nil {
            return nil, &AddrError{Err: "non-IPv4 address", Addr: ip.String()}

It's pretty clear here that the ip.String stored in AddrError is using the wrong ip. This code will always set the Addr field to "<nil>".

The same error occurs a few lines down using To16.

I would send in the obvious fix, but the effect would be to change the Addr field from "<nil>" to "?", which is only barely an improvement. We probably need to fix these cases in ipsock_posix.go and also fix IP.String to produce more useful output for an unrecognized length.

@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Mar 31, 2016


This comment has been minimized.

Copy link
Contributor Author

commented Mar 31, 2016

CC @mikioh


This comment has been minimized.

Copy link

commented Apr 6, 2016

Would it make sense to change the name and replace it with something like

Addr: fmt.Sprintf("%v", origIP)

That will print the IP as a byte array, which is probably the right thing to do rather than have ip.String() return an invalid ip representation?


This comment has been minimized.

Copy link

commented Apr 7, 2016

CL mentions this issue.

@gopherbot gopherbot closed this in 1f54410 Apr 12, 2016

@golang golang locked and limited conversation to collaborators Apr 12, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.