From 0eac462399c8e87bcce252cf058eba9f2678f2bd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 24 Nov 2015 17:59:40 +0100 Subject: resolved: rework dns server lifecycle logic Previously, there was a chance of memory corruption, because when switching to the next DNS server we didn't care whether they linked list of DNS servers was still valid. Clean up lifecycle of the dns server logic: - When a DnsServer object is still in the linked list of DnsServers for a link or the manager, indicate so with a "linked" boolean field, and never follow the linked list if that boolean is not set. - When picking a DnsServer to use for a link ot manager, always explicitly take a reference. This also rearranges some logic, to make the tracking of dns servers by link and globally more alike. --- src/resolve/resolved-conf.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/resolve/resolved-conf.c') diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index 8b49d46a59..fe88006fb7 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -29,8 +29,8 @@ int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char *word) { union in_addr_union address; - DnsServer *first, *s; int family, r; + DnsServer *s; assert(m); assert(word); @@ -39,13 +39,8 @@ int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char if (r < 0) return r; - first = type == DNS_SERVER_FALLBACK ? m->fallback_dns_servers : m->dns_servers; - /* Filter out duplicates */ - LIST_FOREACH(servers, s, first) - if (s->family == family && in_addr_equal(family, &s->address, &address)) - break; - + s = manager_find_dns_server(m, type, family, &address); if (s) { /* * Drop the marker. This is used to find the servers -- cgit v1.2.3-54-g00ecf