1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

resolved: fix strange function recursion

In dns_server_unlink_marked() and dns_server_mark_all() we done recursively.
People might have dozens of servers defined, and it's better to avoid recursion
when a simple loop suffices.

dns_server_unlink_marked() would only unmark the first marked server.

Fixes #19651.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-06-08 18:17:44 +02:00 committed by Lennart Poettering
parent 592d419ce6
commit a77f9dfbae

View File

@ -805,30 +805,30 @@ void dns_server_unlink_all(DnsServer *first) {
dns_server_unlink_all(next);
}
bool dns_server_unlink_marked(DnsServer *first) {
DnsServer *next;
bool changed;
bool dns_server_unlink_marked(DnsServer *server) {
bool changed = false;
if (!first)
return false;
while (server) {
DnsServer *next;
next = first->servers_next;
next = server->servers_next;
if (first->marked) {
changed = true;
dns_server_unlink(first);
} else
changed = false;
if (server->marked) {
dns_server_unlink(server);
changed = true;
}
return changed || dns_server_unlink_marked(next);
server = next;
}
return changed;
}
void dns_server_mark_all(DnsServer *first) {
if (!first)
return;
first->marked = true;
dns_server_mark_all(first->servers_next);
void dns_server_mark_all(DnsServer *server) {
while (server) {
server->marked = true;
server = server->servers_next;
}
}
DnsServer *dns_server_find(DnsServer *first, int family, const union in_addr_union *in_addr, uint16_t port, int ifindex, const char *name) {