mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 09:58:53 -05:00
* Add test for #4755: Nil pointer dereference in State.reattachConfig() * Fix #4755: Add nil check in State.reattachConfig()
This commit is contained in:
@@ -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,
|
||||
|
||||
27
pkg/pluginmanager/state_test.go
Normal file
27
pkg/pluginmanager/state_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user