fix(cron): catch ValueError on NUL paths in lifecycle_guard os.open - #79404
fix(cron): catch ValueError on NUL paths in lifecycle_guard os.open#79404rainbowgore wants to merge 0 commit into
Conversation
Duplicate of #77898 — both catch os.open ValueError for the same embedded-NUL lifecycle-guard path and preserve the existing fail-open result. |
|
补充一个真实生产环境复现案例(Linux / Ubuntu 26.04 LTS),确认此修复对实际触发场景有效: 真实触发场景Hermes gateway 运行中( ls ~/.local/bin/cua-driver 2>/dev/null && ~/.local/bin/cua-driver --version 2>/dev/null | head -1
完整 traceback(生产网关实测)表面现象:terminal 工具报 与 #79398 / #79444 的差异
修复验证应用本 PR 的 补充建议: |
|
Independent reproduction on Linux (Ubuntu 24.04, GCP e2-standard-2, Hermes v0.20.0/v2026.8.3). Trigger: Any command referencing a path-like token that reaches Fix verified locally: Applied the identical # Repro (crashes on main, passes after fix):
from cron.lifecycle_guard import contains_gateway_lifecycle_command_or_referenced_script
contains_gateway_lifecycle_command_or_referenced_script(
".venv/bin/python\x00 -m pip install --quiet polymarket-us",
cwd="/tmp",
) # main: ValueError: embedded null byte → fix: False (no crash)This is the minimal fix consistent with the |
e0a820a to
8f27127
Compare
What does this PR do?
Follow-up to #76762:
_read_referenced_script()incron/lifecycle_guard.pyonly caughtOSErroraroundos.open(path). Paths with an embedded NUL raiseValueError: embedded null byte(CPython), which escaped the guard, crashed the terminal tool, and surfaced asFailed to execute command: embedded null byte.Widen the handler to
except (OSError, ValueError)so the guard fails open (None, False) instead of crashing — same pattern already used at thePath.resolve()site from #76762.Note: open PRs #78572 and #78013 also touch this area (broader NUL hardening). This change is the minimal #79398 fix only.
Related Issue
Fixes #79398
Type of Change
Changes Made
cron/lifecycle_guard.py— catch(OSError, ValueError)onos.openin_read_referenced_scripttests/hermes_cli/test_gateway_restart_loop.py— addtest_nul_bearing_script_path_does_not_crash_guard(issue repro)How to Test
main, run:ValueError: embedded null byteFalsewith no exception.scripts/run_tests.sh tests/hermes_cli/test_gateway_restart_loop.py -q— all tests pass (including the new regression). Confirmhermes gateway restartis still detected as unsafe.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Before (on
main):After:
Made with Cursor