Skip to content

Commit 3f66629

Browse files
committed
Add extra nil checks on cert.Leaf just in case
As follow-up to previous commits
1 parent 5a906ed commit 3f66629

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

certificates.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func (cert Certificate) NeedsRenewal(cfg *Config) bool {
8787
// call it again to see if the cert in storage still needs renewal -- you probably don't want
8888
// to log the second time for checking the cert in storage which is mainly for synchronization.
8989
func (cfg *Config) certNeedsRenewal(leaf *x509.Certificate, ari acme.RenewalInfo, emitLogs bool) bool {
90+
// though this should never happen, safeguard to avoid panics which happened before (since patched; but just in case)
91+
if leaf == nil {
92+
if emitLogs {
93+
cfg.Logger.Error("cannot check if nil leaf cert needs renewal")
94+
}
95+
return false
96+
}
97+
9098
expiration := expiresAt(leaf)
9199

92100
var logger *zap.Logger

handshake.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ func (cfg *Config) handshakeMaintenance(ctx context.Context, hello *tls.ClientHe
561561
zap.String("server_name", hello.ServerName))
562562

563563
renewIfNecessary := func(ctx context.Context, hello *tls.ClientHelloInfo, cert Certificate) (Certificate, error) {
564+
if cert.Leaf == nil {
565+
return cert, fmt.Errorf("leaf certificate is unexpectedly nil: either the Certificate got replaced by an empty value, or it was not properly initialized")
566+
}
564567
if cfg.certNeedsRenewal(cert.Leaf, cert.ari, true) {
565568
// Check if the certificate still exists on disk. If not, we need to obtain a new one.
566569
// This can happen if the certificate was cleaned up by the storage cleaner, but still

0 commit comments

Comments
 (0)