Skip to content

Commit be55a81

Browse files
authored
fix: Backwards compatibility for vex triage (#4421)
* related to #4417 This adds a little bit of backwards compatibility for vex triage * If --triage-input-file is used, display deprecation warning and convert to --vex-file" so scan can continue. * If file extension in .vex, the first time, make a copy and scan anyhow. On subsequent times, print an error asking the user to use --vex-file <new file name> It might be more elegant to edit lib4vex to handle .vex filenames more seamlessly there, but I feel like "give people one chance and then error" is probably more likely to help people switch to the new arguments so we don't have to support the old ones forever and won't break as many CI jobs. Signed-off-by: Terri Oda <[email protected]>
1 parent c252407 commit be55a81

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

cve_bin_tool/cli.py

+34
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import logging
2828
import os
2929
import platform
30+
import shutil
3031
import sys
3132
import textwrap
3233
import time
@@ -64,6 +65,7 @@
6465
InvalidExtensionError,
6566
MirrorError,
6667
PDFOutputUnavailable,
68+
VEXError,
6769
excepthook,
6870
)
6971
from cve_bin_tool.input_engine import InputEngine, TriageData
@@ -544,6 +546,13 @@ def main(argv=None):
544546
)
545547

546548
deprecated_group = parser.add_argument_group("Deprecated")
549+
deprecated_group.add_argument(
550+
"--triage-input-file",
551+
action="store",
552+
help="replaced by --vex-file",
553+
default="",
554+
)
555+
547556
deprecated_group.add_argument(
548557
"-x",
549558
"--extract",
@@ -658,6 +667,31 @@ def main(argv=None):
658667
"""
659668
LOGGER.warning(warning_nolinux)
660669

670+
# warning about deprecated "--triage-input-file" argument
671+
if args["triage_input_file"]:
672+
LOGGER.error(
673+
" --triage-input-file has been deprecated. Please use --vex-file in future."
674+
)
675+
args["vex_file"] = args["triage_input_file"]
676+
if args["vex_file"].endswith(".vex"):
677+
# Auto-switch it to .json
678+
LOGGER.error(".vex extension no longer supported, please use .json")
679+
680+
file_copy = Path(args["vex_file"] + ".cve-bin-tool-auto.json")
681+
original_file = Path(args["vex_file"])
682+
if not file_copy.exists():
683+
LOGGER.error("Trying to make a copy with .json extension for this run.")
684+
LOGGER.error("You will need to use this copy in future scans.")
685+
shutil.copy(original_file, file_copy)
686+
args["vex_file"] = str(file_copy)
687+
else:
688+
# abort and let the user deal with it
689+
LOGGER.error(
690+
"Looks like a previous run of cve-bin-tool already made a copy."
691+
)
692+
LOGGER.error(f"Try re-running with --vex-file {file_copy}")
693+
return ERROR_CODES[VEXError]
694+
661695
# CSVScanner related settings
662696
score = 0
663697
if args["severity"]:

cve_bin_tool/error_handler.py

+5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ class PDFOutputUnavailable(Exception):
149149
"""Raised when reportlab is not installed and PDF output is unavailable"""
150150

151151

152+
class VEXError(Exception):
153+
"""Raised when VEX file provided is invalid"""
154+
155+
152156
class ErrorMode(Enum):
153157
Ignore = 0
154158
NoTrace = 1
@@ -251,4 +255,5 @@ def __exit__(self, exc_type, exc_val, exc_tb):
251255
SigningError: 43,
252256
NetworkConnectionError: 44,
253257
PDFOutputUnavailable: 45,
258+
VEXError: 46,
254259
}

0 commit comments

Comments
 (0)