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

This commit is contained in:
kayos 2023-01-11 04:46:18 -08:00 committed by GitHub
parent ce1163658f
commit c367cca749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 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 {
@ -77,6 +80,10 @@ func (c *HTTPConnector) GetStatus() (status *StatusResponse, err error) {
values = append(values, strings.Split(pair, "=")...)
}
if values == nil || len(values) < 12 {
return nil, ErrInvalidResponseValueLength
}
status = &StatusResponse{}
status.Status = Status(values[1])
status.Serial = values[3]