From 2aede6fa7caf9d273527ae1106e2d9bb0c538942 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 6 May 2022 12:32:26 -0400 Subject: [PATCH] Infinite loop fix Signed-off-by: mark --- vulnerabilities/package_managers.py | 6 +++++- vulnerabilities/tests/test_package_managers.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/vulnerabilities/package_managers.py b/vulnerabilities/package_managers.py index ae98613c1..4f4c7f377 100644 --- a/vulnerabilities/package_managers.py +++ b/vulnerabilities/package_managers.py @@ -660,8 +660,12 @@ def fetch(self, pkg: str) -> Iterable[PackageVersion]: url = f"https://proxy.golang.org/{escaped_pkg}/@v/list" response = get_response(url=url, content_type="text") if not response: - escaped_pkg = self.trim_go_url_path(escaped_pkg) + trimmed_escaped_pkg = self.trim_go_url_path(escaped_pkg) trimmed_pkg = self.trim_go_url_path(trimmed_pkg) or "" + if trimmed_escaped_pkg == escaped_pkg: + break + + escaped_pkg = trimmed_escaped_pkg continue break diff --git a/vulnerabilities/tests/test_package_managers.py b/vulnerabilities/tests/test_package_managers.py index db4e315ec..67cb10b72 100644 --- a/vulnerabilities/tests/test_package_managers.py +++ b/vulnerabilities/tests/test_package_managers.py @@ -300,6 +300,15 @@ def test_fetch(self, mock_fetcher): ] assert results == expected + @mock.patch("vulnerabilities.package_managers.get_response") + def test_fetch_with_responses_are_none(self, mock_fetcher): + # we have many calls made to get_response + responses = [None, None, None, None, None] + mock_fetcher.side_effect = responses + + results = list(GoproxyVersionAPI().fetch("github.com/FerretDB/FerretDB")) + assert results == [] + class TestNugetVersionAPI: expected_versions = [