Skip to content

Commit f5ee005

Browse files
author
Ivana Atanasova
committed
Update ngclient to skip visited nodes on delegation tree traversal
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 #1528 Signed-off-by: Ivana Atanasova <[email protected]>
1 parent bb15ecf commit f5ee005

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tuf/ngclient/updater.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
import logging
6363
import os
6464
import tempfile
65-
from typing import Optional, Set, Tuple
65+
from typing import Optional, Set
6666
from urllib import parse
6767

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

407407
# Preorder depth-first traversal of the graph of target delegations.
408408
while number_of_delegations > 0 and len(delegations_to_visit) > 0:
409409

410410
# Pop the role name from the top of the stack.
411411
role_name, parent_role = delegations_to_visit.pop(-1)
412+
if parent_role not in visited_role_names:
413+
visited_role_names.add(parent_role)
412414

413415
# Skip any visited current role to prevent cycles.
414-
if (role_name, parent_role) in visited_role_names:
416+
if role_name in visited_role_names:
415417
logger.debug("Skipping visited current role %s", role_name)
416418
continue
417419

@@ -427,7 +429,7 @@ def _preorder_depth_first_walk(
427429
return target
428430

429431
# After preorder check, add current role to set of visited roles.
430-
visited_role_names.add((role_name, parent_role))
432+
visited_role_names.add(role_name)
431433

432434
# And also decrement number of visited roles.
433435
number_of_delegations -= 1

0 commit comments

Comments
 (0)