Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ngclient to skip visited nodes on delegation tree traversal #1683

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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