]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Fix for issue #887 (Timeouts to forward servers on BSD based system with ASLR) 894/head
authorPhilip Homburg <philip@nlnetlabs.nl>
Fri, 9 Jun 2023 11:59:31 +0000 (13:59 +0200)
committerPhilip Homburg <philip@nlnetlabs.nl>
Fri, 9 Jun 2023 11:59:31 +0000 (13:59 +0200)
and proabbly #516 (Stream reuse does not work on Windows)

services/outside_network.c

index 2504406670554442a38bc00b94a44ce017451b73..2a219cbc6e9274c01cd4ebc73004ede2b5c56659 100644 (file)
@@ -551,8 +551,27 @@ reuse_tcp_find(struct outside_network* outnet, struct sockaddr_storage* addr,
                log_assert(&key_p != ((struct reuse_tcp*)result)->pending);
        }
        /* not found, return null */
+
+       /* It is possible that we search for something before the first element
+        * in the tree. Replace a null pointer with the first element.
+        */
+       if (!result) {
+               verbose(VERB_CLIENT, "reuse_tcp_find: taking first");
+               result = rbtree_first(&outnet->tcp_reuse);
+       }
+
        if(!result || result == RBTREE_NULL)
                return NULL;
+
+       /* It is possible that we got the previous address, but that the
+        * address we are looking for is in the tree. If the address we got
+        * is less than the address we are looking, then take the next entry.
+        */
+       if (reuse_cmp_addrportssl(result->key, &key_p.reuse) < 0) {
+               verbose(VERB_CLIENT, "reuse_tcp_find: key too low");
+               result = rbtree_next(result);
+       }
+
        verbose(VERB_CLIENT, "reuse_tcp_find check inexact match");
        /* inexact match, find one of possibly several connections to the
         * same destination address, with the correct port, ssl, and