From: Michael Tremer Date: Fri, 27 Jun 2025 13:40:12 +0000 (+0000) Subject: database: Fix backtracking after no match was found at the end of the tree X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95d271bb90b4cebe81c288a95a2336aa63bac4d7;p=location%2Flibloc.git database: Fix backtracking after no match was found at the end of the tree This is a rare bug which only appears if the tree has not been 100% optimised which might happen because it would not be worth the effort to remove all dead ends all of the time. Therefore, we could be reaching a node which is not an actual leaf but still not find our network. In that case, we will have to go backwards slightly to check if there has been a less specific match (but a match nonetheless). This was broken in commit 9e72b8a0c56403ca7d23c6a767d66038e0d63c14 when the return code for no match was changed to zero. Fixes: #13861 - libloc-0.9.18 fails to find some ASN info Reported-by: Adolf Belka Signed-off-by: Michael Tremer --- diff --git a/src/database.c b/src/database.c index 0c86085..c251061 100644 --- a/src/database.c +++ b/src/database.c @@ -907,13 +907,7 @@ static int __loc_database_lookup(struct loc_database* db, const struct in6_addr* // Move on to the next node r = __loc_database_lookup(db, address, network, network_address, node_index, level + 1); - - // End here if a result was found - if (r == 0) - return r; - - // Raise any errors - else if (r < 0) + if (r < 0) return r; DEBUG(db->ctx, "No match found below level %u\n", level); @@ -922,7 +916,7 @@ static int __loc_database_lookup(struct loc_database* db, const struct in6_addr* } // If this node has a leaf, we will check if it matches - if (__loc_database_node_is_leaf(node_v1)) { + if (!*network && __loc_database_node_is_leaf(node_v1)) { r = __loc_database_lookup_handle_leaf(db, address, network, network_address, level, node_v1); if (r < 0) return r;