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

fix: handle disabled_sources in get_vendor_product_pairs #4208

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
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: 3 additions & 5 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,15 +734,12 @@ def main(argv=None):
nvd_api_key=args["nvd_api_key"],
error_mode=error_mode,
)
default_sources = [source_nvd]
default_sources.extend(enabled_sources)
else:
default_sources = enabled_sources
enabled_sources = [source_nvd] + enabled_sources

# Database update related settings
# Connect to the database
cvedb_orig = CVEDB(
sources=default_sources,
sources=enabled_sources,
version_check=not version_check,
error_mode=error_mode,
)
Expand Down Expand Up @@ -1024,6 +1021,7 @@ def main(argv=None):
exclude_folders=args["exclude"],
error_mode=error_mode,
validate=not args["disable_validation_check"],
sources=enabled_sources,
)
version_scanner.remove_skiplist(skips)
LOGGER.info(f"Number of checkers: {version_scanner.number_of_checkers()}")
Expand Down
13 changes: 7 additions & 6 deletions cve_bin_tool/cvedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,15 @@ def get_vendor_product_pairs(self, package_names) -> list[dict[str, str]]:
"""
cursor = self.db_open_and_get_cursor()
vendor_package_pairs = []
query = """
SELECT DISTINCT vendor FROM cve_range
WHERE product=?
"""
query = (
"SELECT DISTINCT vendor FROM cve_range WHERE product=? AND data_source IN (%s)" # nosec
% ",".join("?" for i in self.sources)
)

data_sources = list(map(lambda x: x.source_name, self.sources))
# For python package checkers we don't need the progress bar running
if type(package_names) is not list:
cursor.execute(query, [package_names])
cursor.execute(query, [package_names] + data_sources)
vendors = list(map(lambda x: x[0], cursor.fetchall()))

for vendor in vendors:
Expand All @@ -703,7 +704,7 @@ def get_vendor_product_pairs(self, package_names) -> list[dict[str, str]]:
for package_name in track(
package_names, description="Processing the given list...."
):
cursor.execute(query, [package_name["name"].lower()])
cursor.execute(query, [package_name["name"].lower()] + data_sources)
vendors = list(map(lambda x: x[0], cursor.fetchall()))
for vendor in vendors:
if vendor != "":
Expand Down
3 changes: 2 additions & 1 deletion cve_bin_tool/version_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(
error_mode: ErrorMode = ErrorMode.TruncTrace,
score: int = 0,
validate: bool = True,
sources=None,
):
self.logger = logger or LOGGER.getChild(self.__class__.__name__)
# Update egg if installed in development mode
Expand All @@ -76,7 +77,7 @@ def __init__(
self.should_extract = should_extract
self.file_stack: list[str] = []
self.error_mode = error_mode
self.cve_db = CVEDB()
self.cve_db = CVEDB(sources=sources)
self.validate = validate
# self.logger.info("Checkers loaded: %s" % (", ".join(self.checkers.keys())))
self.language_checkers = self.available_language_checkers()
Expand Down
Loading