Skip to content

Commit e94fa59

Browse files
authored
fix: noscan bug fixes (#5283)
Signed-off-by: joydeep049 <[email protected]>
1 parent 3639196 commit e94fa59

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

cve_bin_tool/cli.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,9 +1164,13 @@ def main(argv=None):
11641164
LOGGER.debug(f"Triage Data: {triage_data}")
11651165
parsed_data[product_info] = triage_data
11661166

1167-
# Always call get_cves to collect component information
1168-
# The method handles both normal and no-scan modes internally
1169-
cve_scanner.get_cves(product_info, triage_data)
1167+
if not args["no_scan"]:
1168+
cve_scanner.get_cves(product_info, triage_data)
1169+
else:
1170+
# In no-scan mode, still populate all_product_data for display
1171+
if product_info not in cve_scanner.all_product_data:
1172+
cve_scanner.all_product_data[product_info] = 0
1173+
cve_scanner.all_product_data[product_info] = 0
11701174
total_files = version_scanner.total_scanned_files
11711175
LOGGER.info(f"Total files: {total_files}")
11721176

cve_bin_tool/output_engine/console.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def _output_console_nowrap(
160160
if all_product_data[product_data] != 0 or no_scan:
161161
if offline:
162162
latest_stable_version = "UNKNOWN (offline mode)"
163+
elif no_scan:
164+
latest_stable_version = "N/A (no-scan mode)"
163165
else:
164166
latest_stable_version = get_latest_upstream_stable_version(
165167
product_data

cve_bin_tool/parsers/parse.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@ def parse(filename, output, cve_db, logger):
9393
Parses the given filename using the appropriate parser.
9494
"""
9595
parsers = []
96+
filename_basename = os.path.basename(filename)
97+
9698
for file in list(valid_files.keys()):
97-
if file in output:
99+
# Check if this file matches a parser pattern
100+
# Either through output (for binary files) or direct filename match (for language files)
101+
if file in output or file == filename_basename:
98102
for valid_file_parser in valid_files[file]:
99103
parsers.append(valid_file_parser(cve_db, logger))
104+
100105
for parser in parsers:
101106
yield from parser.run_checker(filename)

cve_bin_tool/version_scanner.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -262,45 +262,41 @@ def scan_file(self, filename: str) -> Iterator[ScanInfo]:
262262
# check if it's a Linux kernel image
263263
is_linux_kernel, output = self.is_linux_kernel(filename)
264264

265-
# In no-scan mode, also check if it's a language-specific file
266-
is_language_file = False
267-
if self.no_scan:
268-
# Check if filename matches any language parser patterns
269-
for pattern in valid_files.keys():
270-
if pattern in filename:
271-
is_language_file = True
272-
break
265+
# Check if this file matches any language parser patterns
266+
filename_basename = Path(filename).name
267+
is_language_file = filename_basename in self.language_checkers
273268

269+
# In no-scan mode, allow language files even if they're not binary
270+
# In normal mode, require the file to be executable or a language file
274271
if not is_exec and not is_linux_kernel and not is_language_file:
275272
return None
276273

277-
# parse binary file's strings
278-
lines = parse_strings(filename)
274+
# parse binary file's strings (only for binary files)
275+
lines = ""
276+
if is_exec or is_linux_kernel:
277+
lines = parse_strings(filename)
279278

280279
if not self.no_scan and not self.cve_db:
281280
self.logger.info("No Database Object Found: Fallback to No-Scan Mode")
282281

283-
if output:
282+
# Check for language parsers first
283+
if output or is_language_file:
284284
valid_file = False
285285
for file in list(self.language_checkers.keys()):
286-
valid_file = valid_file | (file in output)
286+
valid_file = (
287+
valid_file | (file in output)
288+
if output
289+
else (file == filename_basename)
290+
)
287291
if valid_file:
288-
for scan_info in parse(filename, output, self.cve_db, self.logger):
292+
for scan_info in parse(
293+
filename, output or "", self.cve_db, self.logger
294+
):
289295
yield ScanInfo(scan_info.product_info, "".join(self.file_stack))
290296

291-
# In no-scan mode, also try to parse language-specific files directly
292-
if self.no_scan and is_language_file:
293-
# Create a mock output string that includes the filename pattern
294-
for pattern in valid_files.keys():
295-
if pattern in filename:
296-
mock_output = f"mock: {pattern}"
297-
for scan_info in parse(
298-
filename, mock_output, self.cve_db, self.logger
299-
):
300-
yield ScanInfo(scan_info.product_info, "".join(self.file_stack))
301-
break
302-
303-
yield from self.run_checkers(filename, lines)
297+
# Only run binary checkers on binary files
298+
if is_exec or is_linux_kernel:
299+
yield from self.run_checkers(filename, lines)
304300

305301
def run_checkers(self, filename: str, lines: str) -> Iterator[ScanInfo]:
306302
"""process a Set of checker objects, run them on file lines,

0 commit comments

Comments
 (0)