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: consider rejecting null byte in LookupHost (and similar) on all platforms consistently #37044

Open
dmitshur opened this issue Feb 5, 2020 · 0 comments
Milestone

Comments

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Feb 5, 2020

This is a followup to issues #31597 and #37031.

It is my current understanding that no valid host can contain the null byte ('\x00'), so any such string input is not valid.

net.LookupHost currently operates differently when given an input that contains a null byte. For example, for net.LookupHost("foo\x00bar"):

  • in Go 1.13, on Windows, it caused a panic (#31597)
  • in Go 1.14, on Windows, it returns an error (see here)
  • on macOS with cgo DNS resolver, it does the equivalent of net.LookupHost("foo")
  • on macOS with pure Go DNS resolver, it does something different

It seems that the getaddrinfo C API used on many platforms accepts a null-terminated C-style string and cannot be given a string containing null bytes.

As @ianlancetaylor points out, in the syscall package we reject strings with embedded null bytes, since they won't work with system calls that expect C strings, see syscall.ByteSliceFromString.

Perhaps this is an opportunity to make Go operate more consistently on such inputs on all platforms by reporting an error when the name string contains a null byte. There may be more functions in net that could benefit from this input validation, but to be able to make this change, we need to be confident that this change won't break correct Go programs.

/cc @FiloSottile @ianlancetaylor @mikioh @bradfitz

@dmitshur dmitshur added this to the Backlog milestone Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.