Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic in ParseIPv4 when len(dst) > 4 #1742

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

alexandear
Copy link
Contributor

@alexandear alexandear commented Mar 29, 2024

The PR addresses a panic issue in the ParseIPv4 function when the length of the destination byte slice exceeds 4.

The test case that checks for this issue is testParseIPv4(t, net.IP{0, 0, 0, 0, 0}, "0.0.0.0", true):

=== RUN   TestParseIPv4
=== PAUSE TestParseIPv4
=== CONT  TestParseIPv4
--- FAIL: TestParseIPv4 (0.00s)
panic: BUG: dst must not be nil [recovered]
	panic: BUG: dst must not be nil

In addition to the fix, this PR introduces several negative test cases to enhance the coverage of the ParseIPv4 function:

  • empty ipStr: testParseIPv4(t, nil, "", false);
  • invalid first octet: testParseIPv4(t, nil, "b.1.2.3", false);
  • invalid last octet: testParseIPv4(t, nil, "1.2.3.b", false) and testParseIPv4(t, nil, "1.2.3.456", false).

@erikdubbelboer erikdubbelboer merged commit e28be0c into valyala:master Mar 29, 2024
15 checks passed
@erikdubbelboer
Copy link
Collaborator

Thanks!

@alexandear alexandear deleted the fix/panic-parseipv4 branch March 29, 2024 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants