Prevent an infinite loop in get_recent_address().
authorGuus Sliepen <guus@tinc-vpn.org>
Fri, 30 Mar 2018 09:50:40 +0000 (11:50 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Fri, 30 Mar 2018 09:50:40 +0000 (11:50 +0200)
When a node is offline, but we still have edges to it that have the same
address as we already have in our address cache, an infinite loop would
happen in get_recent_address(), because we forgot to advance the pointer
in the list of known addresses, and kept looking at the same one over
and over.

Thanks to Sven-Haegar Koch for spotting the bug and providing
diagnostics.

src/address_cache.c

index 2fa9baf..389615e 100644 (file)
@@ -129,12 +129,12 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) {
                if(cache->ai) {
                        if(cache->aip) {
                                sockaddr_t *sa = (sockaddr_t *)cache->aip->ai_addr;
+                               cache->aip = cache->aip->ai_next;
 
                                if(find_cached(cache, sa) != NOT_CACHED) {
                                        continue;
                                }
 
-                               cache->aip = cache->aip->ai_next;
                                return sa;
                        } else {
                                free_known_addresses(cache->ai);