Connector: check len(values) to avoid nil pointer dereference (#21)
This commit is contained in:
parent
ce1163658f
commit
c367cca749
|
@ -2,6 +2,7 @@ package connector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -10,6 +11,8 @@ import (
|
||||||
"github.com/certusone/yubihsm-go/commands"
|
"github.com/certusone/yubihsm-go/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrInvalidResponseValueLength = errors.New("invalid response value length")
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// HTTPConnector implements the HTTP based connection with the YubiHSM2 connector
|
// HTTPConnector implements the HTTP based connection with the YubiHSM2 connector
|
||||||
HTTPConnector struct {
|
HTTPConnector struct {
|
||||||
|
@ -77,6 +80,10 @@ func (c *HTTPConnector) GetStatus() (status *StatusResponse, err error) {
|
||||||
values = append(values, strings.Split(pair, "=")...)
|
values = append(values, strings.Split(pair, "=")...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if values == nil || len(values) < 12 {
|
||||||
|
return nil, ErrInvalidResponseValueLength
|
||||||
|
}
|
||||||
|
|
||||||
status = &StatusResponse{}
|
status = &StatusResponse{}
|
||||||
status.Status = Status(values[1])
|
status.Status = Status(values[1])
|
||||||
status.Serial = values[3]
|
status.Serial = values[3]
|
||||||
|
|
Loading…
Reference in New Issue