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()
This commit is contained in:
Nathan Wallace
2025-11-16 15:51:19 -05:00
committed by GitHub
parent b80aaa1727
commit 9d8f135805
2 changed files with 31 additions and 0 deletions

View File

@@ -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,

View File

@@ -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")
}
}