Skip to content

Commit 6eaff43

Browse files
Fix nil pointer dereference on SSH key parser (#130)
* Fix nil pointer dereference on SSH key parser * Restyled by gofmt Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 0e7a9a5 commit 6eaff43

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

iterative/utils/ssh.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/rsa"
66
"crypto/x509"
77
"encoding/pem"
8+
"fmt"
89
"strings"
910
"time"
1011

@@ -27,7 +28,11 @@ func PrivatePEM() (string, error) {
2728
}
2829

2930
func PublicFromPrivatePEM(privateKey string) (string, error) {
30-
block, _ := pem.Decode([]byte(privateKey))
31+
block, rest := pem.Decode([]byte(privateKey))
32+
if block == nil {
33+
return "", fmt.Errorf("Invalid PEM on the SSH private key: %#v", rest)
34+
}
35+
3136
key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
3237
if err != nil {
3338
return "", err

0 commit comments

Comments
 (0)