smx509: ParseCertificatePEM validate type

This commit is contained in:
Sun Yimin 2024-11-19 10:55:41 +08:00 committed by GitHub
parent 1aefd6f1f6
commit c9f55b045f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1063,7 +1063,7 @@ func ParseCertificates(der []byte) ([]*Certificate, error) {
func ParseCertificatePEM(data []byte) (*Certificate, error) { func ParseCertificatePEM(data []byte) (*Certificate, error) {
block, _ := pem.Decode(data) block, _ := pem.Decode(data)
if block == nil { if block == nil || block.Type != "CERTIFICATE" {
return nil, errors.New("x509: failed to decode PEM block containing certificate") return nil, errors.New("x509: failed to decode PEM block containing certificate")
} }
return ParseCertificate(block.Bytes) return ParseCertificate(block.Bytes)