Skip to content

Commit bc95217

Browse files
committed
Validate the address family when parsing Allowed IP nested attributes
Signed-off-by: MrMelon54 <[email protected]>
1 parent b92b7ed commit bc95217

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

internal/wglinux/parse_linux.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,9 @@ func parseAllowedIPs(ipns *[]netip.Prefix) func(ad *netlink.AttributeDecoder) er
140140
// Allowed IP nested attributes.
141141
ad.Nested(func(nad *netlink.AttributeDecoder) error {
142142
var (
143-
ipn netip.Addr
144-
mask int
145-
// TODO: we already have the family stored in ipn, is this needed?
143+
ipn netip.Addr
144+
mask int
146145
family int
147-
_ = family
148146
)
149147

150148
for nad.Next() {
@@ -162,6 +160,19 @@ func parseAllowedIPs(ipns *[]netip.Prefix) func(ad *netlink.AttributeDecoder) er
162160
return err
163161
}
164162

163+
switch family {
164+
case unix.AF_INET:
165+
if !ipn.Is4() {
166+
return fmt.Errorf("decoded IP address does not match the address family")
167+
}
168+
case unix.AF_INET6:
169+
if !ipn.Is6() {
170+
return fmt.Errorf("decoded IP address does not match the address family")
171+
}
172+
default:
173+
return fmt.Errorf("invalid IP address family")
174+
}
175+
165176
ipp := netip.PrefixFrom(ipn, mask)
166177

167178
*ipns = append(*ipns, ipp)

0 commit comments

Comments
 (0)