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: use real filenames in language parsers #4204

Merged
merged 6 commits into from
Jun 19, 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
9 changes: 5 additions & 4 deletions cve_bin_tool/parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: GPL-3.0-or-later

from __future__ import annotations

import re
import sqlite3
from pathlib import Path
from typing import List, Tuple

from packageurl import PackageURL

Expand Down Expand Up @@ -73,7 +74,7 @@ def find_vendor(self, product, version):
# To handle multiple vendors, return all combinations of product/vendor mappings
for v in vendor_package_pair:
vendor = v["vendor"]
location = v.get("location", "/usr/local/bin/product")
location = v.get("location", self.filename)
self.logger.debug(f"{file_path} {product} {version} by {vendor}")
vendorlist.append(
ScanInfo(ProductInfo(vendor, product, version, location), file_path)
Expand All @@ -96,7 +97,7 @@ def generate_purl(self, product, vendor="", qualifier={}, subpath=None):
)
return purl

def find_vendor_from_purl(self, purl, ver) -> Tuple[List[ScanInfo], bool]:
def find_vendor_from_purl(self, purl, ver) -> tuple[list[ScanInfo], bool]:
"""
Finds the vendor information for a given PackageURL (purl) and version from the database.

Expand Down Expand Up @@ -161,7 +162,7 @@ def db_open_and_get_cursor(self) -> sqlite3.Cursor:
raise CVEDBError
return cursor

def decode_cpe23(self, cpe23) -> Tuple[str, str, str]:
def decode_cpe23(self, cpe23) -> tuple[str, str, str]:
"""
Decodes a CPE 2.3 formatted string to extract vendor, product, and version information.

Expand Down
2 changes: 1 addition & 1 deletion cve_bin_tool/parsers/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def find_vendor(self, product, version):
for pair in vendor_package_pair:
vendor = pair["vendor"]
file_path = self.filename
location = pair.get("location", "/usr/local/bin/product")
location = pair.get("location", self.filename)
self.logger.debug(f"{file_path} {product} {version} by {vendor}")
info.append(
ScanInfo(ProductInfo(vendor, product, version, location), file_path)
Expand Down
2 changes: 1 addition & 1 deletion cve_bin_tool/parsers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def run_checker(self, filename):
if vendor_package_pair != []:
for pair in vendor_package_pair:
vendor = pair["vendor"]
location = pair.get("location", "/usr/local/bin/product")
location = pair.get("location", self.filename)
file_path = self.filename
self.logger.debug(
f"{file_path} is {vendor}.{product} {version}"
Expand Down
6 changes: 3 additions & 3 deletions test/test_language_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_python_package(self, filename: str) -> None:
for product in scanner.scan_file(filename):
if product:
product_info, file_path = product
assert product_info == ProductInfo(
"facebook", "zstandard", "0.18.0", "/usr/local/bin/product"
)
assert product_info == ProductInfo(
"facebook", "zstandard", "0.18.0", filename
)
assert file_path == filename
Loading