Skip to content

Fix ndc_read_gen() FIFO hang and marker-write stderr leak (#634, #635) - #641

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/634
Sep 10, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/634

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Summary

Two real code defects in scripts/save-session.sh, both from the gate-3 release audit round.

#634 -- ndc_read_gen() lacked the regular-file type check its sibling ts_marker_read() (#625) already had. A FIFO or character device at $REMEMBER_DIR/tmp/ndc-generation could hang the whole save indefinitely (no O_NONBLOCK, no timeout anywhere in this script), or stream unboundedly for a character device. Backported the same [ ! -f "$NDC_GEN_FILE" ] check: any non-regular-file at that path now reads as unreadable without ever attempting the cat.

#635 -- the two report_error-guarded marker writes added by #625 placed 2>/dev/null after the failing > redirection, which only takes effect once that redirection has already succeeded. Bash's own raw diagnostic (... : Is a directory) leaked into hook-errors.log alongside the intended WARNING, duplicating it. Fixed by wrapping both writes in a { date +%s > "$MARKER"; } 2>/dev/null || ... group -- chose to keep 2>/dev/null (rather than drop it) so behaviour is identical whether or not the caller has already flattened stderr, per the brief's judgment call.

Closes #634, closes #635.

Test plan

  • tests/test_ndc_read_gen_fifo_634.py -- red (5s timeout trip against the unfixed ndc_read_gen()) before the fix, green after; three positive controls (regular file, absent file, dangling symlink) unaffected.
  • tests/test_marker_write_stderr_order_635.py -- red (raw Is a directory diagnostic present in hook-errors.log) before the fix, green after, paired with a positive control that report_error() still fires.
  • Existing tests/test_save_session_marker_unreadable_625.py (12 tests) still green -- no regression to the sibling save-session.sh: the same absent-vs-unreadable collapse #619 fixed for NDC_GEN_FILE is still present at COOLDOWN_MARKER and NDC_MARKER #625 fix this backports from.
  • Narrowed run of 19 save-session.sh / NDC-related test modules (131 tests total) green.
  • python3 .oss/assemble_changelog.py --check -- ok, both 634.fixed.md and 635.fixed.md valid.
  • bash -n scripts/save-session.sh -- syntax OK; shellcheck -x shows no new findings near either edited region.
  • Full pytest suite -- not run locally, per this repo's own CLAUDE.md ("the suite runs locally on demand, never on push" / the gate that blocks a merge is CI across three OSes and four interpreters).

Two adjacent findings, not fixed here

Both of my two self-review spawns (an Explore reviewer and the oss:auditor) independently found the same two classes of further instances of these exact defect shapes in the same file, outside what either issue named. Filing rather than fixing inline: each needs its own judgment call this branch's own brief already left to developer discretion once (wrap vs. drop 2>/dev/null; guard shape for a read), and fixing all of them here would roughly double this diff.

  1. NOW_DAY_FILE read at scripts/save-session.sh:1013 (NDC_DAY=$(cat "$NOW_DAY_FILE" 2>/dev/null | tr -d '[:space:]')) has the same FIFO-hang vulnerability ndc_read_gen() lacks the regular-file type check ts_marker_read() was given, so a FIFO/device at the NDC generation marker path hangs the save indefinitely #634 fixes for NDC_GEN_FILE, immediately adjacent to code this diff touched, with no type-check guard at all. Reproduced: mkfifo dayfifo; timeout 3 bash -c 'cat dayfifo 2>/dev/null | tr -d "[:space:]"' exits 124.
  2. At least five more 2>/dev/null-after-a-failing-> sites, unfixed by this diff: scripts/save-session.sh:397 (COOLDOWN clock-skew self-heal), :879 and :1303 (NOW_DAY_FILE writes), :1001 (NDC clock-skew self-heal, deliberately left alone by this branch since it was outside Guarded marker writes' stderr suppression fires after the write, not before -- "2>/dev/null" on "date +%s > MARKER || ..." leaves the shell's own permission-denied line unsuppressed #635's stated scope), and a structurally different but mechanistically identical if ... > file 2>/dev/null; then shape at :1254. All leak bash's raw diagnostic into hook-errors.log on a directory-in-place-of-marker or permission-denied failure, the same defect Guarded marker writes' stderr suppression fires after the write, not before -- "2>/dev/null" on "date +%s > MARKER || ..." leaves the shell's own permission-denied line unsuppressed #635 fixes at the two sites it names, just without a report_error() to duplicate.

Cross-platform claims

🤖 Generated with Claude Code

https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c

[AI-generated]

#634: ndc_read_gen() lacked the regular-file type check ts_marker_read()
(#625) already had for its own marker. A FIFO or character device at
$REMEMBER_DIR/tmp/ndc-generation could hang the whole save indefinitely
(no O_NONBLOCK, no timeout anywhere in this script) or stream unboundedly.
Backported the same -f check: any non-regular-file at that path now reads
as "unreadable" without ever attempting the cat. Proven with a FIFO test
mirroring test_save_session_marker_unreadable_625.py's own extraction
technique -- red (5s timeout trip) before the fix, green after.

#635: the two guarded marker writes added by #625 placed 2>/dev/null AFTER
the failing `>` redirection, so it suppressed nothing -- bash's own raw
diagnostic ("... : Is a directory") leaked into hook-errors.log alongside
the intended report_error() WARNING, duplicating it. Wrapped both writes
in a `{ ...; }` group so 2>/dev/null applies to the group's own failure too
(kept rather than dropped, so behaviour is identical whether or not the
caller already flattened stderr). Reproduced directly against a directory
marker: red (raw "Is a directory" line present) before the fix, green
after, paired with a positive control that report_error() still fires.

Added tests/test_ndc_read_gen_fifo_634.py and
tests/test_marker_write_stderr_order_635.py, two changelog.d fragments,
and a docs/windows-skip-triage.md row for each new blanket win32 skip.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant