Skip to content

Commit

Permalink
fixup! feat: Server.Run(...) validate addr
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlambrt committed Feb 21, 2024
1 parent 5e34c69 commit d2f9f0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func validateAddr(addr string) (string, error) {
}

// see if we're dealing with a hostname
hostnames, _ := net.LookupHost(rawHost)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
hostnames, _ := net.DefaultResolver.LookupHost(ctx, rawHost)
if len(hostnames) > 0 {
if rawHost == "::1" {
// special case for localhost
Expand Down
5 changes: 5 additions & 0 deletions server_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ func TestValidateAddr(t *testing.T) {
addr: "2001:db8:3333:4444:5555:6666:7777:8888:389",
expected: "2001:db8:3333:4444:5555:6666:7777:8888:389",
},
{
name: "valid-IPv6-literal",
addr: "[2001:db8:3333:4444:5555:6666:7777:8888]:389",
expected: "[2001:db8:3333:4444:5555:6666:7777:8888]:389",
},
{
name: "valid-IPv6-localhost-without-brackets",
addr: "::1:389",
Expand Down

0 comments on commit d2f9f0a

Please sign in to comment.