fix: prevent nil pointer dereference panics in TestClientCertRequired#968
Conversation
Replace t.Errorf with t.Fatalf in error paths where execution would continue and dereference a nil response pointer, causing panics. Also add missing nil guard in ztls comparison logic and fix potential nil result dereference in openssl test. Fixes projectdiscovery#952 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Neo - PR Security ReviewNo security issues found Highlights
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:
WalkthroughTest error handling improvements across three test files replacing non-fatal error reporting with fatal errors to prevent execution continuation after critical failures. Adds nil-dereference guards to prevent panics when TLS handshakes fail and test code attempts to access nil connection state. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Summary
Fixes #952 -
go test ./...panics with nil pointer dereference inTestClientCertRequiredacross three packages.Root cause: Error checks used
t.Errorf(which logs but continues execution) instead oft.Fatalf(which stops the test). WhenConnectWithOptionsor other setup calls fail, the nil response is still dereferenced on the next line, causing a panic.Changes across 3 files:
pkg/tlsx/tls/tls_test.go: Replacet.Errorfwitht.Fatalffor url parsing, dialer init, client init, and ConnectWithOptions errorspkg/tlsx/ztls/ztls_test.go: Samet.Errorf->t.Fatalfchanges, plus add missing nil guard on the finalelse ifbranch (was dereferencing both pointers without checking nil)pkg/tlsx/openssl/openssl_test.go: Replacet.Error/t.Errorfwitht.Fatalffor args building and openssl execution (also fixes potential nilresultdereference inresult.Command)Test plan
go test ./pkg/tlsx/tls/...no longer panics on connection failurego test ./pkg/tlsx/ztls/...no longer panics on connection failurego test ./pkg/tlsx/openssl/...no longer panics on connection failureSummary by CodeRabbit