fix(cron): tolerate NUL bytes in referenced-script paths at os.open

Residual #76762 class: _read_referenced_script caught OSError from
os.open but not ValueError, so a path token carrying an embedded NUL
(tokenized binary-adjacent command text) crashed the terminal tool's
lifecycle guard with 'ValueError: embedded null byte' instead of being
skipped as nothing-to-scan. Reproduced live against main. Same
treatment the resolve()-time site already has; two sabotage-verified
regressions added.
This commit is contained in:
Teknium 2026-08-05 00:06:43 -07:00
parent 5c5f1a6b76
commit 9a9cf6ae83
1 changed files with 15 additions and 0 deletions

View File

@ -695,6 +695,21 @@ class TestLifecycleGuardModule:
)
assert result is False
def test_nul_byte_in_path_token_does_not_crash_guard(self):
"""Residual #76762 class: when a NUL byte survives into the *path
token itself* (tokenized binary-adjacent command text), ``os.open``
raises ValueError not OSError inside
``_read_referenced_script``. The guard must treat it as "nothing to
scan", never crash.
"""
from cron.lifecycle_guard import (
contains_gateway_lifecycle_command_or_referenced_script,
)
result = contains_gateway_lifecycle_command_or_referenced_script(
"bash ./run\x00me.sh", cwd="/tmp"
)
assert result is False
def test_read_referenced_script_tolerates_nul_in_path(self):
"""#77703: _read_referenced_script opens by path. A path with an
embedded NUL byte (a binary's bytes mis-tokenized into a bogus path by