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

Closed
ianlancetaylor opened this issue Mar 31, 2016 · 3 comments
Closed
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

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
@ianlancetaylor
Copy link
Contributor Author

CC @mikioh

@hbhasker
Copy link

hbhasker 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?

@gopherbot
Copy link

CL https://golang.org/cl/21642 mentions this issue.

@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.
Projects
None yet
Development

No branches or pull requests

3 participants