Skip to content

Commit

Permalink
Update ngclient to skip visited nodes on delegation tree traversal
Browse files Browse the repository at this point in the history
This change edits the ngclient `Updater` to traverse the delegation
tree on nodes, instead of edges in order to skip already visited
nodes.

For more detailed clarification, please review
theupdateframework/specification#177

Fixes theupdateframework#1528

Signed-off-by: Ivana Atanasova <iyovcheva@iyovcheva-a02.vmware.com>
  • Loading branch information
Ivana Atanasova committed Nov 18, 2021
1 parent 1b5df4c commit aff96c3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tuf/ngclient/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import logging
import os
import tempfile
from typing import Optional, Set, Tuple
from typing import Optional, Set
from urllib import parse

from securesystemslib import util as sslib_util
Expand Down Expand Up @@ -401,7 +401,7 @@ def _preorder_depth_first_walk(
# List of delegations to be interrogated. A (role, parent role) pair
# is needed to load and verify the delegated targets metadata.
delegations_to_visit = [("targets", "root")]
visited_role_names: Set[Tuple[str, str]] = set()
visited_role_names: Set[str] = set()
number_of_delegations = self.config.max_delegations

# Preorder depth-first traversal of the graph of target delegations.
Expand All @@ -411,7 +411,7 @@ def _preorder_depth_first_walk(
role_name, parent_role = delegations_to_visit.pop(-1)

# Skip any visited current role to prevent cycles.
if (role_name, parent_role) in visited_role_names:
if role_name in visited_role_names:
logger.debug("Skipping visited current role %s", role_name)
continue

Expand All @@ -427,7 +427,7 @@ def _preorder_depth_first_walk(
return target

# After preorder check, add current role to set of visited roles.
visited_role_names.add((role_name, parent_role))
visited_role_names.add(role_name)

# And also decrement number of visited roles.
number_of_delegations -= 1
Expand Down

0 comments on commit aff96c3

Please sign in to comment.