diff --git a/ntp.go b/ntp.go index b764cb3..535a289 100644 --- a/ntp.go +++ b/ntp.go @@ -648,6 +648,10 @@ func dialWrapper(la, ra string, // fixHostPort examines an address in one of the accepted forms and fixes it // to include a port number if necessary. func fixHostPort(address string, defaultPort int) (fixed string, err error) { + if len(address) == 0 { + return "", errors.New("address string is empty") + } + // If the address is wrapped in brackets, append a port if necessary. if address[0] == '[' { end := strings.IndexByte(address, ']') diff --git a/ntp_test.go b/ntp_test.go index 572483a..15dd508 100644 --- a/ntp_test.go +++ b/ntp_test.go @@ -270,6 +270,7 @@ func TestOfflineFixHostPort(t *testing.T) { {"[::ffff:192.168.1.1]", "[::ffff:192.168.1.1]:123", ""}, {"[::ffff:192.168.1.1]:123", "[::ffff:192.168.1.1]:123", ""}, {"[::ffff:192.168.1.1]:1000", "[::ffff:192.168.1.1]:1000", ""}, + {"", "", "address string is empty"}, } for _, c := range cases { fixed, err := fixHostPort(c.address, defaultPort)