Proxy: Fix nil pointer panic in BuildStreamURL and resource leak in ParseBody#4659
Open
sevico wants to merge 2 commits into
Open
Proxy: Fix nil pointer panic in BuildStreamURL and resource leak in ParseBody#4659sevico wants to merge 2 commits into
sevico wants to merge 2 commits into
Conversation
6ce415e to
6ee6f1c
Compare
…arseBody 1. BuildStreamURL: net.ParseIP() returns nil for non-IP hostnames (e.g., "example.com"), then calling nil.To4() panics. Add nil check before calling To4(). 2. ParseBody: defer r.Close() is placed after the ReadAll error check. If ReadAll fails, the function returns early without closing r, causing a resource leak. Move defer to the top of the function.
b9d182c to
e124f9f
Compare
Contributor
|
I rebased your branch to develop branch. |
suzp1984
approved these changes
May 19, 2026
Add TestParseBody_CloseCalledOnReadError to verify r.Close() is called even when ReadAll fails (resource leak fix). Enhance TestBuildStreamURL with: - Comment explaining the example.com case would panic before the nil pointer fix (net.ParseIP returns nil for non-IP hostnames) - IPv6 test cases to verify ip.To4() check works correctly - Clarifying comments for each test case category
Contributor
|
One more thing, I added UT to cover this PR. |
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.
Problem
Two bugs in
internal/utils/utils.go:1. Nil pointer panic in BuildStreamURL
net.ParseIP()returnsnilfor non-IP hostnames (e.g.,"example.com"). The code callsip.To4()without checking ifipis nil first, which causes a panic crash.2. Resource leak in ParseBody
defer r.Close()is placed after theReadAllerror check. IfReadAllfails, the function returns early without the defer being registered, soris never closed.Impact