From: kadu04t <otakurack@gmail.com>
To: luis.augenstein@tngtech.com
Cc: maximilian.huber@tngtech.com, gregkh@linuxfoundation.org,
linux-kernel@vger.kernel.org, kadu04t <otakurack@gmail.com>
Subject: [PATCH] scripts/sbom: catch ValueError from malformed shell quoting
Date: Sat, 18 Jul 2026 15:44:57 -0300 [thread overview]
Message-ID: <20260718184457.1861-1-otakurack@gmail.com> (raw)
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.
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 a malformed quoting command and a command missing a
required positional argument.
Signed-off-by: kadu04t <otakurack@gmail.com>
---
.../savedcmd_parser/savedcmd_parser.py | 2 +-
.../tests/cmd_graph/test_savedcmd_parser.py | 25 +++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/scripts/sbom/sbom/cmd_graph/savedcmd_parser/savedcmd_parser.py b/scripts/sbom/sbom/cmd_graph/savedcmd_parser/savedcmd_parser.py
index 6a7ea4787aa1..d2ca842a7849 100644
--- a/scripts/sbom/sbom/cmd_graph/savedcmd_parser/savedcmd_parser.py
+++ b/scripts/sbom/sbom/cmd_graph/savedcmd_parser/savedcmd_parser.py
@@ -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,
diff --git a/scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py b/scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py
index a061a748e1bf..d7776f072e03 100644
--- a/scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py
+++ b/scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py
@@ -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"
--
2.54.0.windows.1
next reply other threads:[~2026-07-18 18:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 18:44 kadu04t [this message]
2026-07-19 5:24 ` [PATCH] scripts/sbom: catch ValueError from malformed shell quoting Greg KH
2026-07-19 5:24 ` Greg KH
2026-07-19 7:41 ` Carlos Sampaio Ribeiro
[not found] ` <CAGf2LZe-8bRdsRJO2CzbTcOE5X9oDUDzYTRZQM+hLUH5gg8-mQ@mail.gmail.com>
2026-07-19 7:42 ` Greg KH
2026-07-19 8:18 ` [PATCH v2] " Carlos Sampaio Ribeiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260718184457.1861-1-otakurack@gmail.com \
--to=otakurack@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luis.augenstein@tngtech.com \
--cc=maximilian.huber@tngtech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.