mirror of
https://github.com/torvalds/linux.git
synced 2026-09-09 09:22:02 +02:00
scripts/sbom: catch ValueError from malformed shell quoting
parse_inputs_from_commands() only caught CmdParsingError and IndexError
when dispatching to command parsers, but several parsers call
shlex.split() internally, which raises ValueError on malformed shell
quoting (e.g. an unterminated quote). This exception was not caught,
so a single malformed build command would abort SBOM generation
entirely, even with fail_on_unknown_build_command=False, defeating the
purpose of tolerant mode.
The issue was found while reviewing the exception handling around the
saved-command parser after running its existing tests. It can be
reproduced with:
parse_inputs_from_commands('gcc "unterminated',
fail_on_unknown_build_command=False)
Catch ValueError alongside CmdParsingError and IndexError so such
commands are logged as a warning/error and skipped instead of aborting
the whole run.
Add tests covering malformed shell quoting and a missing positional
argument.
Signed-off-by: Carlos Sampaio Ribeiro <otakurack@gmail.com>
Link: https://patch.msgid.link/20260719081859.1001-1-otakurack@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
d07b6f53f0
commit
c16ce856e4
|
|
@ -57,7 +57,7 @@ def parse_inputs_from_commands(
|
|||
try:
|
||||
inputs = matched_parser(single_command)
|
||||
input_files.extend(inputs)
|
||||
except (CmdParsingError, IndexError) as e:
|
||||
except (CmdParsingError, IndexError, ValueError) as e:
|
||||
log_error_or_warning(
|
||||
"Skipped parsing command {single_command} because of command parsing error: {error_message}",
|
||||
single_command=single_command,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,31 @@ class TestSavedCmdParser(unittest.TestCase):
|
|||
errors = sbom_logging._error_logger._message_counts # type: ignore
|
||||
self.assertEqual(errors, {})
|
||||
|
||||
# Error handling tests
|
||||
def test_malformed_shell_quoting(self):
|
||||
command = 'gcc "unterminated'
|
||||
with patch.object(sbom_logging, "warning") as warning:
|
||||
parsed = parse_inputs_from_commands(command, fail_on_unknown_build_command=False)
|
||||
|
||||
self.assertEqual(parsed, [])
|
||||
warning.assert_called_once_with(
|
||||
"Skipped parsing command {single_command} because of command parsing error: {error_message}",
|
||||
single_command=command,
|
||||
error_message="No closing quotation",
|
||||
)
|
||||
|
||||
def test_missing_positional_argument(self):
|
||||
command = "objcopy"
|
||||
with patch.object(sbom_logging, "warning") as warning:
|
||||
parsed = parse_inputs_from_commands(command, fail_on_unknown_build_command=False)
|
||||
|
||||
self.assertEqual(parsed, [])
|
||||
warning.assert_called_once_with(
|
||||
"Skipped parsing command {single_command} because of command parsing error: {error_message}",
|
||||
single_command=command,
|
||||
error_message="list index out of range",
|
||||
)
|
||||
|
||||
# Compound command tests
|
||||
def test_dd_cat(self):
|
||||
cmd = "(dd if=arch/x86/boot/setup.bin bs=4k conv=sync status=none; cat arch/x86/boot/vmlinux.bin) >arch/x86/boot/bzImage"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user