fix: add missing return err after failed ResolveTCPAddr in checkIfIpIsLive - #1008
fix: add missing return err after failed ResolveTCPAddr in checkIfIpIsLive#1008Jah-yee wants to merge 1 commit into
Conversation
…sLive Fixes nil pointer panic when DNS resolution fails for IBM Z/Power host IPs. Before: when net.ResolveTCPAddr returned an error, the function logged it but continued execution with a nil server pointer, causing panic on server.Network() and server.String() calls on line 86. After: returns the error immediately after logging, matching the error-handling pattern used elsewhere in the same function (lines 89 and 93). Signed-off-by: Jah-yee <166608075+Jah-yee@users.noreply.github.com>
PR Summary by QodoFix nil pointer panic in checkIfIpIsLive on DNS resolution failure
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1. checkIfIpIsLive return untested
|
| server, err := net.ResolveTCPAddr("tcp", ip+":22") | ||
| if err != nil { | ||
| log.Error(err, "failed to resolve ip address") | ||
| return err |
There was a problem hiding this comment.
1. checkifipislive return untested 📘 Rule violation ▣ Testability
The new return err line in checkIfIpIsLive is not exercised by existing automated tests, and the IBM unit tests stub out pingFunc, bypassing the real checkIfIpIsLive implementation. This violates the requirement that every modified executable line in the patch is executed by at least one automated test (or has explicit justification).
Agent Prompt
## Issue description
A new executable line was added (`return err`) in `checkIfIpIsLive`, but there is no automated test that executes this line.
## Issue Context
Current IBM unit tests commonly set `pingFunc` to a stub function, which bypasses the real `checkIfIpIsLive` and therefore cannot cover the new error-return behavior.
## Fix Focus Areas
- pkg/ibm/ibmz_helpers.go[78-96]
- pkg/ibm/ibmz_helpers_test.go[1-120]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Bug Description
In
pkg/ibm/ibmz_helpers.go, the functioncheckIfIpIsLivehas a missingreturnstatement after a failednet.ResolveTCPAddrcall. When DNS resolution fails, the error is logged but execution continues to line 86, whereserver.Network()andserver.String()are called on a nilnet.TCPAddr, causing a nil pointer panic.Fix
Add
return errafter the error log on line 84, matching the error-handling pattern used elsewhere in the same function (see lines 89 and 93).Impact
Any DNS resolution failure for an IBM Z or IBM Power host IP address will crash the controller with a nil pointer dereference panic rather than returning a clean error to the caller.
Fixes #985