fix(ztls,auto): fix nil dereference guards and retry counter logic#975
Conversation
Neo - PR Security ReviewNo security issues found Comment |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR improves connection handling resilience in tlsx by refactoring retry logic and strengthening nil-pointer safety. The retry mechanism now uses an indexed for loop with configurable max retries defaulting to 1, and handshake log processing is reorganized with explicit nil guards at multiple levels to prevent unsafe iteration. ChangesConnection Handling Resilience
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
also flagging this , |
|
Also flagging this: in the old code, ClientHello and ServerHello were gated behind the TLSChain option, so if TLSChain was not enabled, these fields would never be populated even if the user asked for them. Moved them out to the top-level hl != nil check so they work correctly regardless of TLSChain. Flagging this because these fields had nothing to do with TLSChain in the first place. |
ac2bbdf to
a0da435
Compare
|
Thanks @cherry-bisht, the ztls nil-guard fix is a real catch and we kept that part as-is. Force-pushed a cleanup that drops the On the retry counter: the original loop reads "Retries = total connection attempts shared across ctls/ztls/openssl", and at the defaults that downstream tools actually use ( Happy to revisit the retry semantics in a follow-up if there's appetite, with the per-engine vs total-budget trade-off called out explicitly in the release notes. |
Changes
ztls: nil dereference guards
All
hlfield accesses were moved inside thehl != nilcheck to preventpotential nil pointer dereference when the handshake log is unavailable.
TLSChainprocessing is also moved inside theServerCertificatesnilcheck to prevent dereference when no certificates are present.
auto: retry counter fix
The shared
retryCounterwas incremented by all three clients in a singleloop pass, meaning at default settings (
Retries=1, forced to 3) eachclient got exactly one attempt and the loop exited — making retries
effectively impossible. Fixed to use a standard
for i := 0; i < maxRetriesloop where each full pass tries all available clients independently.
Testing
go build ./cmd/tlsx/✅go test ./pkg/tlsx/clients/...✅TestClientCertRequiredis unrelated tothese changes (fails on main too)
Summary by CodeRabbit
Release Notes
Bug Fixes
Refactoring