shell tool crashes with a raw ValueError instead of a descriptive ExecutionError when the command contains an embedded NUL byte #181
Labels
No labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Depends on
#183 TDD: shell tool crashes with a raw ValueError instead of a descriptive ExecutionError when the command contains an embedded NUL byte
cleveragents/cleveractors-core
#201 fix(agents): reject shell tool commands containing an embedded NUL byte before spawning a subprocess
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core#181
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Metadata
Commit Message:
fix(agents): reject shell tool commands containing an embedded NUL byte before spawning a subprocessBranch: bugfix/m1-shell-nul-byte-command
Background and context
ToolAgent._execute_shell_command(src/cleveractors/agents/tool.py) is the shared implementation behind theshelltool. Before spawning anything, it only runs_enforce_safe_mode_blocklist, a case-insensitive substring check against a fixed list of dangerous words (rm,del,format,shutdown,reboot,kill). It performs no check that thecommandstring (or theargslist appended to it) is well-formed input for the underlying OS process-spawn call. It then buildscmd_strand callsasyncio.create_subprocess_shell(cmd_str, ...). CPython's subprocess machinery raises a rawValueError("embedded null byte") for any command string containing a NUL byte, before the system shell is ever invoked._execute_shell_command'stryblock around that call only has anexcept asyncio.TimeoutErrorclause — there is noexceptfor anything else — so theValueErroris not caught by_execute_shell_command,_shell_tool, or_execute_tool.This is the same defect class reported in #175 for
file_write(a corrupted/malformed tool argument sails through the tool's own validation and only fails deep inside a lower-level call, with a raw, un-descriptive error) — discovered while auditingfile_read,shell, andpython_execfor the same class of defect, at the maintainer's request, following up on #175/#176/PR #178. (A sibling finding forfile_read, same root pattern but a different code path, is filed separately — see Supporting information.)Current behavior
Confirmed directly against this branch by invoking the tool programmatically:
raises:
This propagates uncaught out of
_execute_shell_command,_shell_tool, and_execute_tool. When the tool agent is driven throughToolAgent.invoke()— the graph-node dispatch entry point — there is no surrounding catch-all, so the rawValueErrorreaches the caller directly instead of the agent'sExecutionErrorcontract. When driven instead throughprocess_message(), the outer genericexcept Exception as ethere does catch and re-wrap it asExecutionError(f"Tool execution failed: {str(e)}"), but the message is still just Python's raw low-level text, with no indication that the command itself was malformed rather than, e.g., a timeout or a non-zero exit.Note for contrast: other forms of malformed/garbled shell input (unterminated quotes, stray markup, etc.) are already handled correctly today — the system shell itself rejects them, and the resulting non-zero exit code and stderr are captured and reported as a clean
ExecutionError(f"Command failed with code {process.returncode}: {error_msg}"). Only the embedded-NUL-byte case bypasses that path entirely, because the crash happens before the shell is ever reached, at the Python/OS exec-argument layer.Expected behavior
_execute_shell_command(shared by_shell_tooland the bundled skill-script execution path) rejects acommandstring containing an embedded NUL byte — and, for theshelltool specifically, anyargsentry that would be concatenated into it — with a descriptiveExecutionError, raised beforeasyncio.create_subprocess_shellis called. The behavior must be identical regardless of which public entry point (invoke()orprocess_message()) dispatches the call.Acceptance criteria
shellcall whosecommandargument (or an entry in itsargslist) contains an embedded NUL byte is rejected with anExecutionErrorbeforeasyncio.create_subprocess_shellis reached.shellis dispatched viaToolAgent.invoke()orToolAgent.process_message()— no rawValueErrorreaches either caller.ExecutionErrormessage names the specific problem found (an embedded NUL byte), not a propagated low-levelValueErrorstring.&&/||chaining, quoting, and the existing safe-mode blocklist behavior — continue to work unchanged; no regression on valid inputs._run_skill_script_commandpath (which usescreate_subprocess_exec, notcreate_subprocess_shell, for bundled skill scripts) is explicitly out of scope for this issue unless shown to share the same crash — confirm whether it does, and note the result in this issue's PR description.Supporting information
ToolAgent._execute_shell_commandinsrc/cleveractors/agents/tool.py. Crash site: the unguardedasyncio.create_subprocess_shell(cmd_str, ...)call, inside atryblock whose onlyexceptclause isasyncio.TimeoutError.file_write's malformed-path defect) and the sibling issue filed for the identical NUL-byte defect infile_read'sos.path.realpath()call — same bug class, different tool, different crash site, filed separately per the project's one-concern-per-issue rule.Subtasks
_execute_shell_commandthat rejects acommand(and, for theshelltool, anyargsentry) containing an embedded NUL byte, raising a descriptiveExecutionError, beforeasyncio.create_subprocess_shellis called._run_skill_script_command'screate_subprocess_execcall shares the same crash for an embedded-NULargventry; if so, apply the equivalent guard there in the same commit, otherwise record the negative finding in the PR description.features/covering ashellcommand containing an embedded NUL byte, both as thecommandvalue and as anargsentry, confirming the failure is anExecutionError(not a rawValueError) from both theinvoke()andprocess_message()entry points, and confirming valid shell commands (pipes, redirects, chaining) remain unaffected.nox -s coverage_report.nox(all default sessions), fix any errors.Definition of Done
This issue is complete when:
Type/TestingTDD issue exists, the TDD scenario (tagged@tdd_expected_fail) is merged first, and this issue's Forgejo dependency correctly shows it depends on that TDD issue.Note for triage
This fits Epic #77 ("LLM Agent Runtime Stabilization") as a tool-dispatch input-validation hardening item, alongside its sibling #175 and the companion
file_readissue found in the same audit — recommend linking it there, but leaving the final call, milestone assignment, and MoSCoW to maintainer/project-owner triage.