Skip to content

Commit 88ee127

Browse files
authored
update parseCertificate() to guarantee version cannot be negative
After the call to ReadOptionalASN1Integer() Version can be really large (e.g., 2,147,483,647) when performing the Version++ on line 823. In that case it would then wrap, leading to a negative Version, which will pass the version check on line 824. This change adds a check to make sure Version is reasonable prior to the increment, thereby guaranteeing it will not wrap.
1 parent bd56cb9 commit 88ee127

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/crypto/x509/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ func parseCertificate(der []byte) (*Certificate, error) {
815815
if !tbs.ReadOptionalASN1Integer(&cert.Version, cryptobyte_asn1.Tag(0).Constructed().ContextSpecific(), 0) {
816816
return nil, errors.New("x509: malformed version")
817817
}
818-
if cert.Version < 0 {
818+
if cert.Version < 0 || cert.Version > 3 {
819819
return nil, errors.New("x509: malformed version")
820820
}
821821
// for backwards compat reasons Version is one-indexed,

0 commit comments

Comments
 (0)