Skip to content

Commit ac7f7d7

Browse files
authored
Merge pull request #1495 from AkihiroSuda/fix-1488
Use net.JoinHostPort
2 parents aedd0c1 + 912c510 commit ac7f7d7

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

pkg/hostagent/dns/dns.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net"
88
"runtime"
9+
"strconv"
910
"strings"
1011
"time"
1112

@@ -318,7 +319,7 @@ func (h *Handler) handleDefault(w dns.ResponseWriter, req *dns.Msg) {
318319
logrus.Tracef("handleDefault for %v", req)
319320
for _, client := range h.clients {
320321
for _, srv := range h.clientConfig.Servers {
321-
addr := fmt.Sprintf("%s:%s", srv, h.clientConfig.Port)
322+
addr := net.JoinHostPort(srv, h.clientConfig.Port)
322323
reply, _, err := client.Exchange(req, addr)
323324
if err != nil {
324325
logrus.WithError(err).Debugf("handleDefault failed to perform a synchronous query with upstream [%v]", addr)
@@ -378,9 +379,9 @@ func listenAndServe(network Network, opts ServerOptions) (*dns.Server, error) {
378379
// always enable reply truncate for UDP
379380
if network == UDP {
380381
opts.HandlerOptions.TruncateReply = true
381-
addr = fmt.Sprintf("%s:%d", opts.Address, opts.UDPPort)
382+
addr = net.JoinHostPort(opts.Address, strconv.Itoa(opts.UDPPort))
382383
} else {
383-
addr = fmt.Sprintf("%s:%d", opts.Address, opts.TCPPort)
384+
addr = net.JoinHostPort(opts.Address, strconv.Itoa(opts.TCPPort))
384385
}
385386
h, err := NewHandler(opts.HandlerOptions)
386387
if err != nil {

pkg/networks/gvisor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func StartGVisorNetstack(ctx context.Context, gVisorOpts *GVisorNetstackOpts) {
5555
SlirpIPAddress: opts.MacAddress,
5656
},
5757
Forwards: map[string]string{
58-
fmt.Sprintf("127.0.0.1:%d", opts.SSHLocalPort): fmt.Sprintf("%s:22", SlirpIPAddress),
58+
fmt.Sprintf("127.0.0.1:%d", opts.SSHLocalPort): net.JoinHostPort(SlirpIPAddress, "22"),
5959
},
6060
DNS: []types.Zone{},
6161
DNSSearchDomains: searchDomains(),

pkg/osutil/dns_darwin.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package osutil
22

33
import (
44
"fmt"
5+
"net"
56
"strings"
67

78
"github.com/lima-vm/lima/pkg/sysprof"
@@ -31,9 +32,9 @@ func proxyURL(proxy string, port interface{}) string {
3132
proxy = "http://" + proxy
3233
}
3334
if portNumber, ok := port.(float64); ok && portNumber != 0 {
34-
proxy = fmt.Sprintf("%s:%.0f", proxy, portNumber)
35+
proxy = net.JoinHostPort(proxy, fmt.Sprintf("%.0f", portNumber))
3536
} else if portString, ok := port.(string); ok && portString != "" {
36-
proxy = fmt.Sprintf("%s:%s", proxy, portString)
37+
proxy = net.JoinHostPort(proxy, portString)
3738
}
3839
return proxy
3940
}

0 commit comments

Comments
 (0)