Skip to content

Commit

Permalink
Merge pull request #79 from openziti/avoid.nil.ref.pem.decode
Browse files Browse the repository at this point in the history
nil check on PEM decode
  • Loading branch information
andrewpmartinez authored Jun 10, 2020
2 parents 9e814e0 + 6c7a8c4 commit bd73d96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion identity/certtools/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ package certtools
import (
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
)

func LoadCert(pemBytes []byte) ([]*x509.Certificate, error) {
certs := make ([]*x509.Certificate, 0)
certs := make([]*x509.Certificate, 0)
var keyBlock *pem.Block
for len(pemBytes) > 0 {
keyBlock, pemBytes = pem.Decode(pemBytes)

if keyBlock == nil {
return nil, errors.New("could not parse")
}

switch keyBlock.Type {
case "CERTIFICATE":
if c, err := x509.ParseCertificate(keyBlock.Bytes); err == nil {
Expand Down
1 change: 1 addition & 0 deletions storage/boltz/typed_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ func (bucket *TypedBucket) setMarshaled(name string, value interface{}) *TypedBu
bucket.SetNil(name)
return bucket
}

switch val := value.(type) {
case string:
bucket.SetString(name, val, nil)
Expand Down

0 comments on commit bd73d96

Please sign in to comment.