E593 libnet/i/defaultipam: improve address pools validation · moby/moby@37ba824 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37ba824

Browse files
committed
libnet/i/defaultipam: improve address pools validation
Nothing was validating whether address pools' `base` prefix were larger than the target subnet `size` they're associated to. As such invalid address pools would yield no subnet, the error could go unnoticed. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
1 parent af30380 commit 37ba824

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

libnetwork/ipams/defaultipam/allocator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ func splitByIPFamily(s []*ipamutils.NetworkToSplit) ([]*ipamutils.NetworkToSplit
9595
if !n.Base.IsValid() || n.Size == 0 {
9696
return []*ipamutils.NetworkToSplit{}, []*ipamutils.NetworkToSplit{}, fmt.Errorf("network at index %d (%v) is not in canonical form", i, n)
9797
}
98+
if n.Base.Bits() > n.Size {
99+
return []*ipamutils.NetworkToSplit{}, []*ipamutils.NetworkToSplit{}, fmt.Errorf("network at index %d (%v) has a smaller prefix (/%d) than the target size of that pool (/%d)", i, n, n.Base.Bits(), n.Size)
100+
}
98101

99102
n.Base, _ = n.Base.Addr().Unmap().Prefix(n.Base.Bits())
100103

0 commit comments

Comments
 (0)
0