Connector: check len(values) to avoid nil pointer dereference

This commit is contained in:
kayos@tcp.direct 2022-06-30 05:33:27 -07:00
parent 43f6e607f2
commit 995af3b2fd
No known key found for this signature in database
GPG Key ID: 4B841471B4BEE979
1 changed files with 8 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package connector
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"net/http"
@ -10,6 +11,8 @@ import (
"github.com/certusone/yubihsm-go/commands"
)
var ErrInvalidResponseValueLength = errors.New("invalid response value length")
type (
// HTTPConnector implements the HTTP based connection with the YubiHSM2 connector
HTTPConnector struct {
@ -66,8 +69,12 @@ func (c *HTTPConnector) GetStatus() (*StatusResponse, error) {
for _, pair := range pairs {
values = append(values, strings.Split(pair, "=")...)
}
status := &StatusResponse{}
if values == nil || len(values) < 12 {
return nil, ErrInvalidResponseValueLength
}
status.Status = Status(values[1])
status.Serial = values[3]
status.Version = values[5]