Skip to content

fix: add missing return err in checkIfIpIsLive to prevent nil pointer panic - #990

Open
123456wda wants to merge 1 commit into
konflux-ci:mainfrom
123456wda:fix/issue-985-nil-pointer-panic-dns-failure
Open

fix: add missing return err in checkIfIpIsLive to prevent nil pointer panic#990
123456wda wants to merge 1 commit into
konflux-ci:mainfrom
123456wda:fix/issue-985-nil-pointer-panic-dns-failure

Conversation

@123456wda

Copy link
Copy Markdown

@

Summary

Fix a nil pointer dereference panic in checkIfIpIsLive when DNS resolution fails.

Problem

In pkg/ibm/ibmz_helpers.go, the function checkIfIpIsLive has a missing return after a failed net.ResolveTCPAddr call. When DNS resolution fails, the error is logged but execution continues to call server.Network() and server.String() on the nil *net.TCPAddr, causing a panic.

Fix

Add a return err after the log.Error call, matching the error-handling pattern used elsewhere in the same function (lines 89 and 93).

Test

Added checkIfIpIsLive test that verifies DNS resolution failure returns an error rather than panicking. The test uses "a b c" (hostname with spaces) which causes net.ResolveTCPAddr to fail deterministically without any network call (0ms).

Verification

go vet ./pkg/ibm/          # passes
go test ./pkg/ibm/ -v      # new test passes

Fixes #985

🤖 Generated with Claude Code
@

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 konflux-ci#985

Co-Authored-By: Claude Code <noreply@anthropic.com>
@
@qodo-app-for-konflux-ci

Copy link
Copy Markdown

PR Summary by Qodo

Fix nil pointer panic on DNS resolution failure in checkIfIpIsLive

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Return early when ResolveTCPAddr fails to avoid nil pointer dereference.
• Add a unit test ensuring DNS resolution errors are returned (no panic).
• Use an invalid hostname to make the failure deterministic and local-only.
Diagram

graph TD
  A[Caller] --> B["checkIfIpIsLive"] --> C["net.ResolveTCPAddr"] --> D{"Resolved?"}
  D -->|"no"| G["return err"]
  D -->|"yes"| E["net.DialTimeout"] --> F["nil / err"]
Loading
High-Level Assessment

The early-return fix is the correct and minimal change: it aligns with existing error-handling branches in the same function and prevents dereferencing a nil *net.TCPAddr. The added regression test appropriately targets the failure mode without relying on external network conditions.

Files changed (2) +15 / -0

Bug fix (1) +1 / -0
ibmz_helpers.goReturn error after failed TCP address resolution +1/-0

Return error after failed TCP address resolution

• Adds a missing 'return err' after 'net.ResolveTCPAddr' fails so the function does not continue with a nil '*net.TCPAddr'. This prevents a nil pointer dereference when DNS/host resolution fails.

pkg/ibm/ibmz_helpers.go

Tests (1) +14 / -0
ibmz_helpers_test.goAdd regression test for DNS resolution failure in checkIfIpIsLive +14/-0

Add regression test for DNS resolution failure in checkIfIpIsLive

• Introduces a test that passes an invalid hostname containing spaces to force 'net.ResolveTCPAddr' to fail immediately. Asserts the function returns an error (and does not panic).

pkg/ibm/ibmz_helpers_test.go

@fullsend-ai-review

fullsend-ai-review Bot commented Jul 29, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 1:53 PM UTC · Completed 2:04 PM UTC
Commit: 37b10e4 · View workflow run →

@qodo-app-for-konflux-ci

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

@fullsend-ai-review

Copy link
Copy Markdown

Looks good to me


Labels: Bug fix adding missing error return in IBM cloud provider package — minimal scope, low risk

@fullsend-ai-review fullsend-ai-review Bot added ready-for-merge All reviewers approved — ready to merge bug Something isn't working semver/patch Semver patch version bump Review effort 1/5 risk/low AI-assessed low risk dependency update labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready-for-merge All reviewers approved — ready to merge Review effort 1/5 risk/low AI-assessed low risk dependency update semver/patch Semver patch version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Missing error return in checkIfIpIsLive causes nil pointer panic on DNS resolution failure

1 participant