From 9d8f13580549fa7ad246bd7d1fc7bc71f29a9108 Mon Sep 17 00:00:00 2001 From: Nathan Wallace Date: Sun, 16 Nov 2025 15:51:19 -0500 Subject: [PATCH] Nil pointer dereference in State.reattachConfig() closes #4755 (#4893) * Add test for #4755: Nil pointer dereference in State.reattachConfig() * Fix #4755: Add nil check in State.reattachConfig() --- pkg/pluginmanager/state.go | 4 ++++ pkg/pluginmanager/state_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 pkg/pluginmanager/state_test.go diff --git a/pkg/pluginmanager/state.go b/pkg/pluginmanager/state.go index 7b05742de..745805669 100644 --- a/pkg/pluginmanager/state.go +++ b/pkg/pluginmanager/state.go @@ -86,6 +86,10 @@ func (s *State) Save() error { } func (s *State) reattachConfig() *plugin.ReattachConfig { + // if Addr is nil, we cannot create a valid reattach config + if s.Addr == nil { + return nil + } return &plugin.ReattachConfig{ Protocol: s.Protocol, ProtocolVersion: s.ProtocolVersion, diff --git a/pkg/pluginmanager/state_test.go b/pkg/pluginmanager/state_test.go new file mode 100644 index 000000000..877174699 --- /dev/null +++ b/pkg/pluginmanager/state_test.go @@ -0,0 +1,27 @@ +package pluginmanager + +import ( + "testing" + + "github.com/hashicorp/go-plugin" +) + +// TestStateWithNilAddr tests that reattachConfig handles nil Addr gracefully +// This test demonstrates bug #4755 +func TestStateWithNilAddr(t *testing.T) { + state := &State{ + Protocol: plugin.ProtocolGRPC, + ProtocolVersion: 1, + Pid: 12345, + Executable: "/usr/local/bin/steampipe", + Addr: nil, // Nil address - this will cause panic without fix + } + + // This should not panic - it should return nil gracefully + config := state.reattachConfig() + + // With nil Addr, we expect nil config (not a panic) + if config != nil { + t.Error("Expected nil reattach config when Addr is nil") + } +}