Skip to content

Commit

Permalink
fix overflow on 32bit machines
Browse files Browse the repository at this point in the history
  • Loading branch information
c-robinson committed Jan 7, 2024
1 parent 00a2086 commit 3415cb7
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions net6.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (n Net6) Enumerate(size, offset int) []net.IP {
return nil
}

count := getEnumerationCount(size, offset, n.Count())
count := getEnumerationCount(uint(size), uint(offset), n.Count())

// Handle edge-case mask sizes
ones, _ := n.Mask().Size()
Expand All @@ -155,21 +155,21 @@ func (n Net6) Enumerate(size, offset int) []net.IP {
// our worker-pool based on request size; and [b] don't have to worry
// about exhausting some upper bound of goroutines -- enumerate requests
// are limited to MaxUint32, so we won't generate more than 65536
limit := 65535
pos := 0
var limit uint = 65535
var pos uint = 0
wg := sync.WaitGroup{}
for pos < count {
incr := limit
if limit > count-pos {
incr = count - pos
}
wg.Add(1)
go func(fip net.IP, pos, count int) {
go func(fip net.IP, pos, count uint) {
defer wg.Done()
firstip := CopyIP(fip)
lpos := pos
addrs[lpos], _ = IncrementIP6WithinHostmask(firstip, n.Hostmask, uint128.New(uint64(lpos), 0))
for i := 1; i < count; i++ {
for i := uint(1); i < count; i++ {
lpos++
addrs[lpos], _ = NextIP6WithinHostmask(addrs[lpos-1], n.Hostmask)
}
Expand Down Expand Up @@ -360,13 +360,13 @@ func (n Net6) wildcard() net.IPMask {

// getEnumerationCount returns the size of the array needed to satisfy an
// Enumerate request. Mostly split out to ease testing of larger values
func getEnumerationCount(reqSize, offset int, count uint128.Uint128) int {
sizes := []int{math.MaxUint32}
func getEnumerationCount(reqSize, offset uint, count uint128.Uint128) uint {
sizes := []uint{math.MaxUint32}

if count.Cmp64(math.MaxUint32) <= 0 {
realCount := 0
if int(count.Lo) > offset {
realCount = int(count.Lo) - offset
var realCount uint = 0
if uint(count.Lo) > offset {
realCount = uint(count.Lo) - offset
}
sizes = append(sizes, realCount)
}
Expand Down

0 comments on commit 3415cb7

Please sign in to comment.