Skip to content

The agent that grows with you

fix(cron): coerce script_path to str in the NUL guard so it can never crash (#86829, review #86832)

SHT795e035f6013
diff --git a/cron/scheduler.py b/cron/scheduler.py
index a6cab6a6ee2..1f77030000f 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -3204,7 +3204,11 @@ def _run_job_script(
# Path operations raise ValueError *after* expanduser (expanduser never
# expands "~user" there, so the try below never fires) — reject eagerly
# so both platforms fail cleanly instead of crashing the scheduler.
- if "\x00" in script_path:
+ # str() first so the guard itself can never raise TypeError on a
+ # non-str script_path (e.g. a Path passed by a future caller) — the
+ # guard must be crash-proof even though every current call site
+ # passes a plain str (#86832 review).
+ if "\x00" in str(script_path):
return False, f"Blocked: script path contains a NUL byte: {script_path!r}"
try:
diff --git a/tests/cron/test_cron_no_agent.py b/tests/cron/test_cron_no_agent.py
index 728f9f54d1a..fc8614c33d1 100644
--- a/tests/cron/test_cron_no_agent.py
+++ b/tests/cron/test_cron_no_agent.py
@@ -12,6 +12,7 @@ Covers:
from __future__ import annotations
import json
+import pathlib
import subprocess
from unittest.mock import patch
@@ -294,6 +295,24 @@ def test_run_job_script_nul_rejected_before_any_path_call(hermes_env, monkeypatc
assert "NUL byte" in output
+def test_run_job_script_accepts_pathlike_script_path(hermes_env):
+ """The eager NUL guard must not crash on a non-str script_path.
+
+ ``"\x00" in script_path`` raises TypeError for a pathlib.Path (not
+ iterable), so a Path passed by a future caller would crash the
+ scheduler at the guard itself. The guard coerces with str() first;
+ a valid Path must still run the script end-to-end (regression for
+ the #86832 review point)."""
+ from cron.scheduler import _run_job_script
+
+ script = hermes_env / "scripts" / "probe.py"
+ script.write_text('print("pathlike ok")\n', encoding="utf-8")
+
+ ok, output = _run_job_script(pathlib.Path(script))
+ assert ok is True
+ assert "pathlike ok" in output
+
+
# ---------------------------------------------------------------------------
# _summarize_cron_failure_for_delivery: mode-aware failure attribution
# ---------------------------------------------------------------------------