Merge pull request #10607 from yuwata/fix-10605

network: fix segfault in manager_free()
This commit is contained in:
Evgeny Vereshchagin 2018-11-02 02:52:53 +03:00 committed by GitHub
commit 9cbdf5db48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 10 deletions

View File

@ -785,7 +785,7 @@ static int link_set_routing_policy_rule(Link *link) {
LIST_FOREACH(rules, rule, link->network->rules) {
r = routing_policy_rule_get(link->manager, rule->family, &rule->from, rule->from_prefixlen, &rule->to,
rule->to_prefixlen, rule->tos, rule->fwmark, rule->table, rule->iif, rule->oif, &rrule);
if (r == 1) {
if (r == 0) {
(void) routing_policy_rule_make_local(link->manager, rrule);
continue;
}

View File

@ -1451,8 +1451,10 @@ void manager_free(Manager *m) {
while ((pool = m->address_pools))
address_pool_free(pool);
set_free_with_destructor(m->rules, routing_policy_rule_free);
set_free_with_destructor(m->rules_foreign, routing_policy_rule_free);
/* routing_policy_rule_free() access m->rules and m->rules_foreign.
* So, it is necessary to set NULL after the sets are freed. */
m->rules = set_free_with_destructor(m->rules, routing_policy_rule_free);
m->rules_foreign = set_free_with_destructor(m->rules_foreign, routing_policy_rule_free);
set_free_with_destructor(m->rules_saved, routing_policy_rule_free);
sd_event_unref(m->event);

View File

@ -92,9 +92,11 @@ void prefix_free(Prefix *prefix) {
assert(prefix->network->n_static_prefixes > 0);
prefix->network->n_static_prefixes--;
if (prefix->section)
if (prefix->section) {
hashmap_remove(prefix->network->prefixes_by_section,
prefix->section);
network_config_section_free(prefix->section);
}
}
prefix->radv_prefix = sd_radv_prefix_unref(prefix->radv_prefix);

View File

@ -79,10 +79,10 @@ static void routing_policy_rule_hash_func(const void *b, struct siphash *state)
siphash24_compress(&rule->table, sizeof(rule->table), state);
if (rule->iif)
siphash24_compress(&rule->iif, strlen(rule->iif), state);
siphash24_compress(rule->iif, strlen(rule->iif), state);
if (rule->oif)
siphash24_compress(&rule->oif, strlen(rule->oif), state);
siphash24_compress(rule->oif, strlen(rule->oif), state);
break;
default:
@ -188,7 +188,7 @@ int routing_policy_rule_get(Manager *m,
if (existing) {
if (ret)
*ret = existing;
return 1;
return 0;
}
return -ENOENT;
@ -257,8 +257,8 @@ static int routing_policy_rule_add_internal(Manager *m,
rule->tos = tos;
rule->fwmark = fwmark;
rule->table = table;
rule->iif = TAKE_PTR(iif);
rule->oif = TAKE_PTR(oif);
rule->iif = iif;
rule->oif = oif;
r = set_ensure_allocated(rules, &routing_policy_rule_hash_ops);
if (r < 0)
@ -272,6 +272,7 @@ static int routing_policy_rule_add_internal(Manager *m,
*ret = rule;
rule = NULL;
iif = oif = NULL;
return 0;
}
@ -549,7 +550,7 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, sd_netlin
r = routing_policy_rule_add(link->manager, rule->family, &rule->from, rule->from_prefixlen, &rule->to,
rule->to_prefixlen, rule->tos, rule->fwmark, rule->table, rule->iif, rule->oif, NULL);
if (r < 0)
return log_error_errno(r, "Could not add rule : %m");
return log_error_errno(r, "Could not add rule: %m");
return 0;
}