Skip to contentSkip to conversation

dhcp-transport: Do not leak fds during bind

PATCH Applied Denis Kenzior 1 participant 2 messages May 16, 2022 – May 18, 2022

lore
Share & tools
lore

Denis Kenzior

author
#0 lore raw

PATCH 1/1 dhcp-transport: Do not leak fds during bind

When a lease is renewed, the transport bind operation is called. This can be done multiple times by dhcp_client, whenever a lease has been obtained or renewed. This can result in fds being leaked.

If bind operation has previously succeeded, simply return and reuse the already created fd.

---
 ell/dhcp-transport.c | 4 ++++
 1 file changed, 4 insertions(+)
ell/dhcp-transport.c +4 -0
index 52da2db04f49..b466f136972c 100644
@@ -361,6 +361,9 @@ static int _dhcp_default_transport_bind(struct dhcp_transport *s,
 	if (!transport->io)
 		return -EIO;
 
+	if (transport->udp_fd >= 0)
+		return 0;
+
 	fd = kernel_udp_socket_open(transport->ifname, saddr, transport->port);
 	if (fd < 0)
 		return fd;
@@ -552,6 +555,7 @@ struct dhcp_transport *_dhcp_default_transport_new(uint32_t ifindex,
 	transport->super.ifindex = ifindex;
 	l_strlcpy(transport->ifname, ifname, IFNAMSIZ);
 	transport->port = port;
+	transport->udp_fd = -1;
 
 	return &transport->super;
 }
Signature · 1 line
2.32.0
author Applied
#1 lore raw
Quoted 10 lines · Denis Kenzior

When a lease is renewed, the transport bind operation is called. This can be done multiple times by dhcp_client, whenever a lease has been obtained or renewed. This can result in fds being leaked.

If bind operation has previously succeeded, simply return and reuse the already created fd.

---
  ell/dhcp-transport.c | 4 ++++
  1 file changed, 4 insertions(+)

Applied.