]> git.ipfire.org Git - location/libloc.git/commitdiff
database: Fix backtracking after no match was found at the end of the tree
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 13:40:12 +0000 (13:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 13:48:34 +0000 (13:48 +0000)
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 <adolf.belka@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c

index 0c8608542aaad6e82c4d8602bbeb388ab43225bb..c251061cc8a254879491ebe133b1b4f3b58ddf30 100644 (file)
@@ -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;