From: Yu Watanabe Date: Wed, 16 Mar 2022 12:16:54 +0000 (+0900) Subject: sd-radv: do not use iterater outside of the loop X-Git-Tag: v251-rc1~132^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56aa51432e0dd284f202c327f29b74cf2b10734a;p=thirdparty%2Fsystemd.git sd-radv: do not use iterater outside of the loop --- diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c index 752c09d8907..56ccd4867c7 100644 --- a/src/libsystemd-network/sd-radv.c +++ b/src/libsystemd-network/sd-radv.c @@ -578,8 +578,7 @@ int sd_radv_set_preference(sd_radv *ra, unsigned preference) { int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { _cleanup_free_ char *addr_p = NULL; - sd_radv_prefix *cur; - bool update = false; + sd_radv_prefix *cur, *found = NULL; int r; assert_return(ra, -EINVAL); @@ -604,7 +603,7 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { continue; if (cur->opt.prefixlen == p->opt.prefixlen) { - update = true; + found = cur; break; } @@ -615,15 +614,13 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { strna(addr_p), strna(addr_cur)); } - if (update) { - assert(cur); - + if (found) { /* p and cur may be equivalent. First increment the reference counter. */ sd_radv_prefix_ref(p); /* Then, remove the old entry. */ - LIST_REMOVE(prefix, ra->prefixes, cur); - sd_radv_prefix_unref(cur); + LIST_REMOVE(prefix, ra->prefixes, found); + sd_radv_prefix_unref(found); /* Finally, add the new entry. */ LIST_APPEND(prefix, ra->prefixes, p); @@ -688,8 +685,7 @@ void sd_radv_remove_prefix( int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { _cleanup_free_ char *addr_p = NULL; - sd_radv_route_prefix *cur; - bool update = false; + sd_radv_route_prefix *cur, *found = NULL; int r; assert_return(ra, -EINVAL); @@ -710,7 +706,7 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { continue; if (cur->opt.prefixlen == p->opt.prefixlen) { - update = true; + found = cur; break; } @@ -721,15 +717,13 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { strna(addr_p), strna(addr_cur)); } - if (update) { - assert(cur); - + if (found) { /* p and cur may be equivalent. First increment the reference counter. */ sd_radv_route_prefix_ref(p); /* Then, remove the old entry. */ - LIST_REMOVE(prefix, ra->route_prefixes, cur); - sd_radv_route_prefix_unref(cur); + LIST_REMOVE(prefix, ra->route_prefixes, found); + sd_radv_route_prefix_unref(found); /* Finally, add the new entry. */ LIST_APPEND(prefix, ra->route_prefixes, p);