diff mbox series

[4/4] netconfig: Fix leaking domain name string

Message ID 20220701133237.2887854-4-andrew.zaborowski@intel.com (mailing list archive)
State Accepted, archived
Headers show
Series [1/4] dhcp: Set lease->bound_time before emitting event | expand

Commit Message

Andrew Zaborowski July 1, 2022, 1:32 p.m. UTC
In l_netconfig_get_domain_names we had two
l_dhcp_lease_get_domain_name() calls and only saved one of the values.
l_dhcp_lease_get_domain_name() internally does an strdup so we own the
returned string.

Reported by Coverity Scan as CID 379209.
---
 ell/netconfig.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/ell/netconfig.c b/ell/netconfig.c
index f48018b..28afa9b 100644
--- a/ell/netconfig.c
+++ b/ell/netconfig.c
@@ -1908,15 +1908,16 @@  LIB_EXPORT char **l_netconfig_get_domain_names(struct l_netconfig *netconfig)
 	char **ret = NULL;
 	const struct l_dhcp_lease *v4_lease;
 	const struct l_dhcp6_lease *v6_lease;
+	char *dn;
 
 	if (netconfig->v4_domain_names_override)
 		netconfig_strv_cat(&ret, netconfig->v4_domain_names_override,
 					false);
 	else if ((v4_lease =
 			l_dhcp_client_get_lease(netconfig->dhcp_client)) &&
-			l_dhcp_lease_get_domain_name(v4_lease)) {
+			(dn = l_dhcp_lease_get_domain_name(v4_lease))) {
 		ret = l_new(char *, 2);
-		ret[0] = l_dhcp_lease_get_domain_name(v4_lease);
+		ret[0] = dn;
 	}
 
 	if (netconfig->v6_dns_override)