|
4 | 4 | import os
|
5 | 5 | import subprocess
|
6 | 6 | import sys
|
| 7 | +from re import search |
7 | 8 |
|
8 | 9 | import pkg_resources
|
9 | 10 |
|
|
12 | 13 | from cve_bin_tool.extractor import Extractor
|
13 | 14 | from cve_bin_tool.file import is_binary
|
14 | 15 | from cve_bin_tool.log import LOGGER
|
| 16 | +from cve_bin_tool.package_list_parser.vendor_fetch import VendorFetch |
15 | 17 | from cve_bin_tool.strings import Strings
|
16 | 18 | from cve_bin_tool.util import DirWalk, ProductInfo, inpath
|
17 | 19 |
|
@@ -145,9 +147,34 @@ def scan_file(self, filename):
|
145 | 147 | lines[0] = (
|
146 | 148 | "--generated pattern for cve-bin-tool " + lines[0] + " " + lines[1]
|
147 | 149 | )
|
| 150 | + yield from self.run_python_package_checkers(filename, lines) |
148 | 151 |
|
149 | 152 | yield from self.run_checkers(filename, lines)
|
150 | 153 |
|
| 154 | + def run_python_package_checkers(self, filename, lines): |
| 155 | + """ |
| 156 | + This function runs only for python packages. |
| 157 | + There are no actual checkers. |
| 158 | + The ProductInfo is computed without the help of any checkers from PKG-INFO or METADATA. |
| 159 | + """ |
| 160 | + product = search( |
| 161 | + r"--generated pattern for cve-bin-tool Name: (.+?) Version:", lines[0] |
| 162 | + ).group(1) |
| 163 | + version = search(r"Version: (.+?)$", lines[1]).group(1) |
| 164 | + |
| 165 | + with VendorFetch() as vendor_fetch: |
| 166 | + vendor_package_pair = vendor_fetch.get_vendor_product_pairs(product) |
| 167 | + |
| 168 | + if vendor_package_pair != []: |
| 169 | + vendor = vendor_package_pair[0]["vendor"] |
| 170 | + file_path = "".join(self.file_stack) |
| 171 | + |
| 172 | + self.logger.info(f"{file_path} is {product} {version}") |
| 173 | + |
| 174 | + yield ProductInfo(vendor, product, version), file_path |
| 175 | + |
| 176 | + self.logger.debug(f"Done scanning file: {filename}") |
| 177 | + |
151 | 178 | def run_checkers(self, filename, lines):
|
152 | 179 | # tko
|
153 | 180 | for (dummy_checker_name, checker) in self.checkers.items():
|
|
0 commit comments