* [PATCH] scripts/sbom: catch ValueError from malformed shell quoting
@ 2026-07-18 18:44 kadu04t
2026-07-19 5:24 ` Greg KH
2026-07-19 5:24 ` Greg KH
0 siblings, 2 replies; 6+ messages in thread
From: kadu04t @ 2026-07-18 18:44 UTC (permalink / raw)
To: luis.augenstein; +Cc: maximilian.huber, gregkh, linux-kernel, kadu04t
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] scripts/sbom: catch ValueError from malformed shell quoting
2026-07-18 18:44 [PATCH] scripts/sbom: catch ValueError from malformed shell quoting kadu04t
@ 2026-07-19 5:24 ` Greg KH
2026-07-19 5:24 ` Greg KH
1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2026-07-19 5:24 UTC (permalink / raw)
To: kadu04t; +Cc: luis.augenstein, maximilian.huber, linux-kernel
On Sat, Jul 18, 2026 at 03:44:57PM -0300, kadu04t wrote:
> 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>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- It looks like you did not use your "real" name for the patch on either
the Signed-off-by: line, or the From: line (both of which have to
match). Please read the kernel file,
Documentation/process/submitting-patches.rst for how to do this
correctly.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] scripts/sbom: catch ValueError from malformed shell quoting
2026-07-18 18:44 [PATCH] scripts/sbom: catch ValueError from malformed shell quoting kadu04t
2026-07-19 5:24 ` 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>
1 sibling, 2 replies; 6+ messages in thread
From: Greg KH @ 2026-07-19 5:24 UTC (permalink / raw)
To: kadu04t; +Cc: luis.augenstein, maximilian.huber, linux-kernel
On Sat, Jul 18, 2026 at 03:44:57PM -0300, kadu04t wrote:
> 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.
Do we have this today in the build system?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] scripts/sbom: catch ValueError from malformed shell quoting
2026-07-19 5:24 ` Greg KH
@ 2026-07-19 7:41 ` Carlos Sampaio Ribeiro
[not found] ` <CAGf2LZe-8bRdsRJO2CzbTcOE5X9oDUDzYTRZQM+hLUH5gg8-mQ@mail.gmail.com>
1 sibling, 0 replies; 6+ messages in thread
From: Carlos Sampaio Ribeiro @ 2026-07-19 7:41 UTC (permalink / raw)
To: Greg KH; +Cc: luis.augenstein, maximilian.huber, linux-kernel
On Sun, Jul 19, 2026 at 02:24:17AM -0300, Greg KH wrote:
> Do we have this today in the build system?
Sorry for my previous reply only to you.
I'm still learning the Linux kernel mailing list workflow.
The code path exists in the current implementation because the SBOM
generator parses the .cmd files generated by Kbuild.
However, I have not observed malformed .cmd files produced by a normal
kernel build. My intention with this patch was to make the parser behave
consistently in tolerant mode (fail_on_unknown_build_command=False) when
given malformed or corrupted inputs, rather than to fix an issue known to
occur during standard kernel builds.
Thanks,
Carlos
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] scripts/sbom: catch ValueError from malformed shell quoting
[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
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2026-07-19 7:42 UTC (permalink / raw)
To: Carlos Eduardo; +Cc: luis.augenstein, maximilian.huber, linux-kernel
On Sun, Jul 19, 2026 at 04:26:57AM -0300, Carlos Eduardo wrote:
> On Sun, Jul 19, 2026 at 02:24:17AM -0300, Greg KH wrote:
> > Do we have this today in the build system?
>
> Sorry for my previous reply. I'm still learning the Linux kernel mailing
> list workflow.
This was sent in html format, which the lists reject :(
> The code path exists in the current implementation because the SBOM
> generator parses the .cmd files generated by Kbuild.
>
> However, I have not observed malformed .cmd files produced by a normal
> kernel build. My intention with this patch was to make the parser behave
> consistently in tolerant mode (fail_on_unknown_build_command=False) when
> given malformed or corrupted inputs, rather than to fix an issue known to
> occur during standard kernel builds.
Ok, that's fine, just wanted to check if this is needed to fix a bug
today, but you are just making this more "robust".
And how did you find this bug?
Can you include that information in your changelog text and fix up the
authorship/signed-off-by information?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] scripts/sbom: catch ValueError from malformed shell quoting
2026-07-19 7:42 ` Greg KH
@ 2026-07-19 8:18 ` Carlos Sampaio Ribeiro
0 siblings, 0 replies; 6+ messages in thread
From: Carlos Sampaio Ribeiro @ 2026-07-19 8:18 UTC (permalink / raw)
To: Greg KH; +Cc: luis.augenstein, maximilian.huber, linux-kernel
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>
---
Changes in v2:
- Use my real name in the From and Signed-off-by fields.
- Explain how the missing ValueError handling was found.
.../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
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-19 8:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-18 18:44 [PATCH] scripts/sbom: catch ValueError from malformed shell quoting kadu04t
2026-07-19 5:24 ` 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
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.