Skip to content

Commit d75566b

Browse files
hdurand0710mjuraga
authored andcommitted
BUG/MEDIUM: fixes when client runtime is nil
Ensure that we always check is c.runtime is valid before any use of c.runtime
1 parent bfa575d commit d75566b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

runtime/runtime_client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,18 @@ func (c *client) initWithMasterSocket(opt options.RuntimeOptions) error {
7979

8080
// GetStats returns stats from the socket
8181
func (c *client) GetStats() models.NativeStats {
82+
if !c.runtime.IsValid() {
83+
return models.NativeStats{}
84+
}
8285
result := c.runtime.GetStats()
8386
return result
8487
}
8588

8689
// GetInfo returns info from the socket
8790
func (c *client) GetInfo() (models.ProcessInfo, error) {
91+
if !c.runtime.IsValid() {
92+
return models.ProcessInfo{}, errors.New("no valid runtime found")
93+
}
8894
result := c.runtime.GetInfo()
8995
return result, nil
9096
}
@@ -104,6 +110,9 @@ func (c *client) GetVersion() (HAProxyVersion, error) {
104110
_, err, _ = versionSfg.Do(versionKey, func() (interface{}, error) {
105111
version := &HAProxyVersion{}
106112
var response string
113+
if !c.runtime.IsValid() {
114+
return HAProxyVersion{}, errors.New("no valid runtime found")
115+
}
107116
response, err = c.runtime.ExecuteRaw("show info")
108117
if err != nil {
109118
return HAProxyVersion{}, err
@@ -155,6 +164,9 @@ func (c *client) Reload() (string, error) {
155164
return "", fmt.Errorf("cannot reload: requires HAProxy 2.7 or later but current version is %v", haproxyVersion)
156165
}
157166

167+
if !c.runtime.IsValid() {
168+
return "", errors.New("cannot reload: no valid runtime found")
169+
}
158170
output, err := c.runtime.ExecuteMaster("reload")
159171
if err != nil {
160172
return "", fmt.Errorf("cannot reload: %w", err)

runtime/runtime_single_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type SingleRuntime struct {
4343
}
4444

4545
func (s *SingleRuntime) IsValid() bool {
46-
return s.socketPath != ""
46+
return s != nil && s.socketPath != ""
4747
}
4848

4949
// Init must be given path to runtime socket and a flag to indicate if it's in master-worker mode.

0 commit comments

Comments
 (0)