Skip to content

Commit 3b73a5a

Browse files
authored
Add nil check to isPrecertificate (#187)
1 parent d5c47cf commit 3b73a5a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

internal/scti/chain_validation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func NewChainValidationOpts(trustedRoots *x509util.PEMCertPool, rejectExpired, r
124124
// An error is returned if the CT extension is present but is not ASN.1 NULL as defined
125125
// by the spec.
126126
func isPrecertificate(cert *x509.Certificate) (bool, error) {
127+
if cert == nil {
128+
return false, errors.New("nil certificate")
129+
}
130+
127131
for _, ext := range cert.Extensions {
128132
if x509.OIDExtensionCTPoison.Equal(ext.Id) {
129133
if !ext.Critical || !bytes.Equal(asn1.NullBytes, ext.Value) {

internal/scti/chain_validation_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ func TestIsPrecertificate(t *testing.T) {
212212
wantPrecert: false,
213213
wantErr: true,
214214
},
215+
{
216+
desc: "nil-cert",
217+
cert: nil,
218+
wantPrecert: false,
219+
wantErr: true,
220+
},
215221
}
216222

217223
for _, test := range tests {

0 commit comments

Comments
 (0)