Skip to content

Commit 0ef3fd3

Browse files
committed
fix: update location handling
Do not use find_product_location to set the location field in version_scanner.py as otherwise cve-bin-tool will try to find the location of the product on the host system (which is obviously wrong). Instead, set the location to be the file_path relative to the rootdir that was given to cve-bin-tool Fix #4396 Signed-off-by: Fabrice Fontaine <[email protected]>
1 parent 3029cb0 commit 0ef3fd3

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

cve_bin_tool/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ def main(argv=None):
10881088
error_mode=error_mode,
10891089
validate=not args["disable_validation_check"],
10901090
sources=enabled_sources,
1091+
rootdir=args["directory"],
10911092
)
10921093
version_scanner.remove_skiplist(skips)
10931094
LOGGER.info(f"Number of checkers: {version_scanner.number_of_checkers()}")

cve_bin_tool/version_scanner.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@
1717
from cve_bin_tool.log import LOGGER
1818
from cve_bin_tool.parsers.parse import available_parsers, parse, valid_files
1919
from cve_bin_tool.strings import parse_strings
20-
from cve_bin_tool.util import (
21-
DirWalk,
22-
ProductInfo,
23-
ScanInfo,
24-
find_product_location,
25-
inpath,
26-
validate_location,
27-
)
20+
from cve_bin_tool.util import DirWalk, ProductInfo, ScanInfo, inpath
2821

2922
if sys.version_info >= (3, 10):
3023
from importlib import metadata as importlib_metadata
@@ -51,6 +44,7 @@ def __init__(
5144
score: int = 0,
5245
validate: bool = True,
5346
sources=None,
47+
rootdir=None,
5448
):
5549
self.logger = logger or LOGGER.getChild(self.__class__.__name__)
5650
# Update egg if installed in development mode
@@ -77,6 +71,7 @@ def __init__(
7771
self.validate = validate
7872
# self.logger.info("Checkers loaded: %s" % (", ".join(self.checkers.keys())))
7973
self.language_checkers = self.available_language_checkers()
74+
self.rootdir = rootdir
8075

8176
@classmethod
8277
def load_checkers(cls) -> dict[str, type[Checker]]:
@@ -288,13 +283,9 @@ def run_checkers(self, filename: str, lines: str) -> Iterator[ScanInfo]:
288283
f'{file_path} {result["is_or_contains"]} {dummy_checker_name} {version}'
289284
)
290285
for vendor, product in checker.VENDOR_PRODUCT:
291-
location = find_product_location(product)
292-
if location is None:
293-
location = "NotFound"
294-
if validate_location(location) is False:
295-
raise ValueError(
296-
f"Invalid location {location} for {product}"
297-
)
286+
location = "/" + str(
287+
Path(file_path).relative_to(Path(self.rootdir))
288+
)
298289
yield ScanInfo(
299290
ProductInfo(vendor, product, version, location),
300291
file_path,

0 commit comments

Comments
 (0)