Skip to content

Commit b7ae35e

Browse files
authored
refactor: use JoinHostPort for vnc tcp dialing (#541)
Replace manual `"%s:%d"` address formatting with `net.JoinHostPort` when dialing VNC. This ensures host/port strings are constructed correctly (including IPv6 hosts) and avoids malformed TCP target addresses. Write VMX entries directly into the output buffer instead of formatting an intermediate string first. This avoids unnecessary allocations while preserving the same encoded output. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
1 parent b4dbafb commit b7ae35e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

builder/vmware/common/step_vnc_connect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (s *StepVNCConnect) ConnectVNC(ctx context.Context, state multistep.StateBa
4646
vncPort := state.Get("vnc_port").(int)
4747
vncPassword := state.Get("vnc_password")
4848

49-
nc, err := net.Dial("tcp", fmt.Sprintf("%s:%d", vncIp, vncPort))
49+
nc, err := net.Dial("tcp", net.JoinHostPort(vncIp, fmt.Sprintf("%d", vncPort)))
5050
if err != nil {
5151
err := fmt.Errorf("error connecting to VNC: %s", err)
5252
state.Put("error", err)

builder/vmware/common/vmx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func EncodeVMX(contents map[string]string) string {
7373
for _, c := range caseSensitive {
7474
key = strings.Replace(key, strings.ToLower(c), c, 1)
7575
}
76-
buf.WriteString(fmt.Sprintf(pat, key, contents[k]))
76+
fmt.Fprintf(&buf, pat, key, contents[k])
7777
}
7878

7979
return buf.String()

0 commit comments

Comments
 (0)