mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
ssh pubkey parsing: prevent segfault
Fixes an issue where the apiserver would segfault when parsing an ssh public key that isn't PEM encoded.
This commit is contained in:
parent
6bda989d54
commit
1b5aa2c09c
@ -277,6 +277,9 @@ func ParsePublicKeyFromFile(keyFile string) (*rsa.PublicKey, error) {
|
|||||||
return nil, fmt.Errorf("error reading SSH key %s: '%v'", keyFile, err)
|
return nil, fmt.Errorf("error reading SSH key %s: '%v'", keyFile, err)
|
||||||
}
|
}
|
||||||
keyBlock, _ := pem.Decode(buffer)
|
keyBlock, _ := pem.Decode(buffer)
|
||||||
|
if keyBlock == nil {
|
||||||
|
return nil, fmt.Errorf("error parsing SSH key %s: 'invalid PEM format'", keyFile)
|
||||||
|
}
|
||||||
key, err := x509.ParsePKIXPublicKey(keyBlock.Bytes)
|
key, err := x509.ParsePKIXPublicKey(keyBlock.Bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error parsing SSH key %s: '%v'", keyFile, err)
|
return nil, fmt.Errorf("error parsing SSH key %s: '%v'", keyFile, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user