Fix nil pointer dereference in Collector.handleOnError#887
Open
Shinku-Chen wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Collector.handleOnErrordereferencedresponse.StatusCodebeforethe nil-guard that synthesized a fallback
Response. Short-circuitevaluation of
err == nil && ...masked the bug whenevererrwasnon-nil, but the
err == nil && response == nilpath — the exactcase the existing nil-guard was clearly written to defend against —
panicked with
runtime error: invalid memory address or nil pointer dereference.This MR reorders the function so the nil-guard runs first, ensuring
every subsequent field access (including the debugger event that
reads
response.StatusCode) operates on a validResponse.Changes
colly.go: move theresponse == nilcheck to the top ofhandleOnError, before anyresponse.StatusCodeaccess.colly_test.go: addTestHandleOnErrorNilResponsewith twosubtests:
nil response with transport error—(nil, err)returned bythe backend on DNS/connection failures.
nil response with nil error— reproduces the original panic;fails on
master, passes with this fix.Test plan
go test -run TestHandleOnErrorNilResponse -v .passes.go test ./...— full suite green.colly.go, re-ran, observedruntime error: invalid memory address or nil pointer dereference).Risk
Low. The reordering is behavior-preserving for all paths that
previously did not panic: when
response != nil, the new code takesthe same branches as before. The only behavioral change is that
calls with
response == nilno longer crash and instead proceedwith the synthesized
Responsethe original author had alreadyprepared.
Backward compatibility
No API changes. No exported signatures modified.