Skip to content

Commit

Permalink
Fixed IPRange::Glob#each when * is in a IPv6 range (closes #486).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Feb 11, 2024
1 parent 0076802 commit 7e5a347
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
8 changes: 5 additions & 3 deletions lib/ronin/support/network/ip_range/glob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,19 @@ def initialize(string)
@base = 16
@formatter = method(:format_ipv6_address)

separator = ':'
separator = ':'
octet_range = (0..0xffff)
else # IPv4
@version = 4
@base = 10
@formatter = method(:format_ipv4_address)

separator = '.'
separator = '.'
octet_range = (0..255)
end

@ranges = @string.split(separator).map do |segment|
if segment == '*' then (0..255)
if segment == '*' then octet_range
elsif segment.include?(',') then parse_list(segment)
elsif segment.include?('-') then parse_range(segment)
else [segment]
Expand Down
24 changes: 16 additions & 8 deletions spec/network/ip_range/glob_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@
context "and when the IP address is a v6 address" do
let(:glob) { "fe80::abc:*" }
let(:addresses) do
(0..255).map { |d| "fe80::abc:%x" % d }
(0..0xffff).map { |d| "fe80::abc:%x" % d }
end

it "must expand '*' globs to 01-fe" do
expect { |b|
subject.each(glob,&b)
}.to yield_successive_args(*addresses)
yielded_addresses = []

subject.each(glob) do |address|
yielded_addresses << address
end

expect(yielded_addresses).to eq(addresses)
end

context "but no block is given" do
Expand Down Expand Up @@ -214,13 +218,17 @@
context "and when the IP address is a v6 address" do
let(:glob) { "fe80::abc:*" }
let(:addresses) do
(0..255).map { |d| "fe80::abc:%x" % d }
(0..0xffff).map { |d| "fe80::abc:%x" % d }
end

it "must expand '*' globs to 01-fe" do
expect { |b|
subject.each(&b)
}.to yield_successive_args(*addresses)
yielded_addresses = []

subject.each do |address|
yielded_addresses << address
end

expect(yielded_addresses).to eq(addresses)
end

context "but no block is given" do
Expand Down
24 changes: 16 additions & 8 deletions spec/network/ip_range_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@
context "and when the IP address is a v6 address" do
let(:glob) { "fe80::abc:*" }
let(:addresses) do
(0..255).map { |d| "fe80::abc:%x" % d }
(0..0xffff).map { |d| "fe80::abc:%x" % d }
end

it "must expand '*' globs to 01-fe" do
expect { |b|
subject.each(glob,&b)
}.to yield_successive_args(*addresses)
yielded_addresses = []

subject.each(glob) do |address|
yielded_addresses << address
end

expect(yielded_addresses).to eq(addresses)
end

context "but no block is given" do
Expand Down Expand Up @@ -319,13 +323,17 @@
context "and when the IP address is a v6 address" do
let(:glob) { "fe80::abc:*" }
let(:addresses) do
(0..255).map { |d| "fe80::abc:%x" % d }
(0..0xffff).map { |d| "fe80::abc:%x" % d }
end

it "must expand '*' globs to 01-fe" do
expect { |b|
subject.each(&b)
}.to yield_successive_args(*addresses)
yielded_addresses = []

subject.each do |address|
yielded_addresses << address
end

expect(yielded_addresses).to eq(addresses)
end

context "but no block is given" do
Expand Down

0 comments on commit 7e5a347

Please sign in to comment.