summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/server4/conn.go
diff options
context:
space:
mode:
authorAnatole Denis <natolumin@unverle.fr>2019-10-15 11:16:29 +0200
committerAnatole Denis <natolumin@unverle.fr>2019-10-15 11:19:43 +0200
commit4a980462f24f67f989ac2860fcf9879aef3e3fa0 (patch)
tree21214730f7dec53c3c226554535a4bc7b8db2888 /dhcpv4/server4/conn.go
parent62a3f6317a49b19232e67faa31d90f94b522eb82 (diff)
server4: Only allow IPv4 addresses
IPv6 addresses would not cause a crash, but would silently listen on the wildcard address instead of the passed address, which is surprising at best. Instead check for the address family and reject non-v4 addresses Signed-off-by: Anatole Denis <natolumin@unverle.fr>
Diffstat (limited to 'dhcpv4/server4/conn.go')
-rw-r--r--dhcpv4/server4/conn.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/dhcpv4/server4/conn.go b/dhcpv4/server4/conn.go
index d62a5ac..3e49669 100644
--- a/dhcpv4/server4/conn.go
+++ b/dhcpv4/server4/conn.go
@@ -43,6 +43,9 @@ func NewIPv4UDPConn(iface string, addr *net.UDPAddr) (*net.UDPConn, error) {
}
// Bind to the port.
saddr := unix.SockaddrInet4{Port: addr.Port}
+ if addr.IP != nil && addr.IP.To4() == nil {
+ return nil, fmt.Errorf("wrong address family (expected v4) for %s", addr.IP)
+ }
copy(saddr.Addr[:], addr.IP.To4())
if err := unix.Bind(fd, &saddr); err != nil {
return nil, fmt.Errorf("cannot bind to port %d: %v", addr.Port, err)