From 0fb7734c9f5db618680fa11f9cb2201d27913728 Mon Sep 17 00:00:00 2001 From: 123456wda Date: Wed, 29 Jul 2026 21:52:06 +0800 Subject: [PATCH] @ fix: add missing return err in checkIfIpIsLive to prevent nil pointer panic When net.ResolveTCPAddr fails in checkIfIpIsLive, the error was logged but execution continued to call server.Network() and server.String() on the nil *net.TCPAddr pointer, causing a nil pointer dereference panic. Add a return err statement after the log.Error call on line 84, matching the error-handling pattern used elsewhere in the same function (lines 89 and 93). Fixes #985 Co-Authored-By: Claude Code @ --- pkg/ibm/ibmz_helpers.go | 1 + pkg/ibm/ibmz_helpers_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/ibm/ibmz_helpers.go b/pkg/ibm/ibmz_helpers.go index 8f6dee5b0..ed2822ab1 100644 --- a/pkg/ibm/ibmz_helpers.go +++ b/pkg/ibm/ibmz_helpers.go @@ -82,6 +82,7 @@ func checkIfIpIsLive(ctx context.Context, ip string) error { server, err := net.ResolveTCPAddr("tcp", ip+":22") if err != nil { log.Error(err, "failed to resolve ip address") + return err } conn, err := net.DialTimeout(server.Network(), server.String(), 5*time.Second) if err != nil { diff --git a/pkg/ibm/ibmz_helpers_test.go b/pkg/ibm/ibmz_helpers_test.go index c7d73d747..0cf43f636 100644 --- a/pkg/ibm/ibmz_helpers_test.go +++ b/pkg/ibm/ibmz_helpers_test.go @@ -1,6 +1,7 @@ package ibm import ( + "context" "fmt" "regexp" @@ -101,4 +102,17 @@ var _ = Describe("IBM s390x Helper Functions", func() { "System Z Max Tag Length"), ) }) + + Describe("The checkIfIpIsLive function", func() { + When("the DNS resolution of the host fails", func() { + It("should return an error instead of panicking", func() { + ctx := context.Background() + // "a b c" contains spaces, which are invalid in DNS names + // — this causes net.ResolveTCPAddr to fail immediately + // (0ms, pure local resolution) without any network call. + err := checkIfIpIsLive(ctx, "a b c") + Expect(err).Should(HaveOccurred()) + }) + }) + }) })