-
Notifications
You must be signed in to change notification settings - Fork 361
Fix protocol mismatch when manually specifying v4+v6 --local-addr #679
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
Merged
phillip-stephens
merged 6 commits into
zmap:master
from
FineTralfazz:fix/local-addr-protocol-mismatch
Mar 31, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b7cd61
Fix multi-protocol source IP selection
FineTralfazz ef33eed
Tests
FineTralfazz 25b29c0
comment wrapping
FineTralfazz 12d20a0
Merge branch 'master' into fix/local-addr-protocol-mismatch
phillip-stephens 6eb7e0f
Fixed PR comments, make filtering function more predictable and guard…
phillip-stephens eb093a7
Merge branch 'master' into fix/local-addr-protocol-mismatch
phillip-stephens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package zgrab2 | ||
|
|
||
| import ( | ||
| "net" | ||
| "testing" | ||
| ) | ||
|
|
||
| var ( | ||
| testIPv4a = net.ParseIP("192.168.1.1") | ||
| testIPv4b = net.ParseIP("192.168.1.2") | ||
| testIPv6a = net.ParseIP("2001:db8::1") | ||
| testIPv6b = net.ParseIP("2001:db8::2") | ||
| testTargetIPv4 = net.ParseIP("192.168.1.100") | ||
| testTargetIPv6 = net.ParseIP("2001:db8::100") | ||
| ) | ||
|
|
||
| func TestFilterLocalAddrsByFamily_IPv4Target(t *testing.T) { | ||
| result := filterLocalAddrsByFamily([]net.IP{testIPv4a, testIPv6a, testIPv4b, testIPv6b}, testTargetIPv4) | ||
| if len(result) != 2 { | ||
| t.Fatalf("expected 2 IPv4 addresses, got %d: %v", len(result), result) | ||
| } | ||
| for _, ip := range result { | ||
| if ip.To4() == nil { | ||
| t.Errorf("expected only IPv4 addresses, got %s", ip) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestFilterLocalAddrsByFamily_IPv6Target(t *testing.T) { | ||
| result := filterLocalAddrsByFamily([]net.IP{testIPv4a, testIPv6a, testIPv6b}, testTargetIPv6) | ||
| if len(result) != 2 { | ||
| t.Fatalf("expected 2 IPv6 addresses, got %d: %v", len(result), result) | ||
| } | ||
| for _, ip := range result { | ||
| if ip.To4() != nil { | ||
| t.Errorf("expected only IPv6 addresses, got %s", ip) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestFilterLocalAddrsByFamily_NilTarget(t *testing.T) { | ||
| result := filterLocalAddrsByFamily([]net.IP{testIPv4a, testIPv6a}, nil) | ||
| if len(result) != 2 { | ||
| t.Fatalf("expected all addresses returned when target is nil, got %d", len(result)) | ||
| } | ||
| } | ||
|
|
||
| func TestFilterLocalAddrsByFamily_NoMatchFallsBack(t *testing.T) { | ||
| result := filterLocalAddrsByFamily([]net.IP{testIPv6a, testIPv6b}, testTargetIPv4) | ||
| if len(result) != 0 { | ||
| t.Fatalf("expected empty list, got %d: %v", len(result), result) | ||
| } | ||
| } | ||
|
|
||
| func TestFilterLocalAddrsByFamily_EmptyInput(t *testing.T) { | ||
| result := filterLocalAddrsByFamily(nil, testTargetIPv4) | ||
| if len(result) != 0 { | ||
| t.Fatalf("expected empty result for nil input, got %d", len(result)) | ||
| } | ||
|
|
||
| result = filterLocalAddrsByFamily([]net.IP{}, testTargetIPv4) | ||
| if len(result) != 0 { | ||
| t.Fatalf("expected empty result for empty input, got %d", len(result)) | ||
| } | ||
| } | ||
|
|
||
| func TestFilterLocalAddrsByFamily_AllSameFamily(t *testing.T) { | ||
| result := filterLocalAddrsByFamily([]net.IP{testIPv4a, testIPv4b}, testTargetIPv4) | ||
| if len(result) != 2 { | ||
| t.Fatalf("expected 2 addresses when all match, got %d", len(result)) | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rand.Intnwill panic of called withn <= 0. I'd suggest we add a check to be sure the list's size is > 0. (Note - this is really only an issue when combined with my above suggestion, since as you've written it I don't think we'd hit this case)