Skip to content

fix(daemon): strip batch flags + explicit goodbye flush + arg rejection error - #5609

Merged
oferchen merged 2 commits into
masterfrom
fix/uts-15-batch-mode-daemon-arg-defense
Jun 11, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/uts-15-batch-mode-daemon-arg-defense

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • UTS-15.b (docs(crates): rustdoc cleanup for branding embedding apple-fs windows-gnu-eh test-support #3729): defensive strip of --write-batch / --only-write-batch / --read-batch from the daemon-bound argv built by build_full_daemon_args. Mirrors upstream options.c:server_options() which never emits these client-only flags to the server; the strip is defense-in-depth so a future refactor that forwards remote_options or any other user-supplied list into the daemon path cannot silently leak them.
  • UTS-15.c (docs(protocol): rustdoc cleanup for legacy module #3730): explicit writer.flush() at the end of GeneratorContext::run() after the goodbye handshake. Mirrors upstream main.c:912 client_run() / main.c:968 do_server_sender() calling io_flush(FULL_FLUSH) immediately before return, so NDX_DONE plus any trailing multiplex frames are durable before the transport FIN.
  • UTS-15.g (feat(cli): add --simd flag for runtime SIMD level override #3743): apply_long_form_args() now returns the first client-only batch flag it encounters; build_server_config() surfaces it via rsync_warning! plus an explicit @ERROR: <flag>: unrecognized option (in daemon mode) frame and a non-zero exit, mirroring upstream options.c:1444-1449 daemon-mode rejection. Rule 12 fail-loud: silent close on unknown args is no longer possible.
  • Adds docs/audits/uts-15-batch-mode-daemon-arg-defense.md capturing the three invariants and upstream references.

Symptom these three together fix: the upstream batch-mode interop pattern where a client invocation like oc-rsync --write-batch=PATH ... against an oc-rsync daemon previously drove a silent connection close at protocol byte ~2241725 with no actionable diagnostic.

Test plan

  • Argv-sanitiser: cargo nextest run -p core --all-features -E 'test(build_full_args_strips_) + test(strips_bare_write_batch) + test(strips_kv_write_batch) + test(strips_kv_read_batch) + test(strips_only_write_batch) + test(leaves_non_batch_args_alone) + test(does_not_swallow_next_flag_when_two_arg_value_missing) + test(build_full_args_default_path_emits_no_batch_flags) + test(build_full_args_strips_read_batch_flag_and_orphan_value) + test(build_full_args_strips_only_write_batch_flag)' - assert all batch-flag forms (bare, key=value, two-arg) are stripped from the daemon argv and the default builder path emits no batch tokens.
  • Goodbye flush: cargo nextest run -p transfer --all-features -E 'test(handle_goodbye_proto31_flushes_ndx_done_before_close)' - the FlushTrackingWriter confirms NDX_DONE is the last byte before close, at least one flush() occurred, and the final recorded operation is a flush (not a partial write).
  • Daemon arg rejection: cargo nextest run -p daemon --all-features -E 'test(apply_long_form_args_reports_write_batch) + test(apply_long_form_args_reports_read_batch) + test(apply_long_form_args_reports_only_write_batch) + test(apply_long_form_args_recognised_args_do_not_report_unknown) + test(apply_long_form_args_positional_paths_are_not_classified)' - assert each batch flag is surfaced as the unknown-arg offender, recognised args (delete/temp-dir/link-dest/compact flag strings) do NOT trip the surface, and positional paths containing a literal --write-batch=... past the . separator are correctly classified as paths rather than options.

…on error

Three independent defenses for the upstream batch-mode interop pattern where
the daemon receives client-only flags it cannot handle, currently leading to
a silent connection close at protocol byte ~2241725:

- UTS-15.b: strip --write-batch / --only-write-batch / --read-batch in
  build_full_daemon_args() so they can never reach the daemon argv, even
  if a future refactor wires remote_options or another forwarded list
  into the daemon path. Mirrors upstream options.c:server_options() which
  intentionally omits these client-local flags from server argv.
- UTS-15.c: explicit writer.flush() at the end of GeneratorContext::run()
  after the goodbye handshake. Mirrors upstream main.c:912 client_run()
  and main.c:968 do_server_sender() io_flush(FULL_FLUSH) before return,
  so NDX_DONE never races the transport FIN. Errors propagate unless the
  peer already closed.
- UTS-15.g: apply_long_form_args() now returns the first client-only
  batch flag it encounters; build_server_config() surfaces it via
  rsync_warning! + @error frame + non-zero exit, mirroring upstream
  options.c:1444-1449 "(in daemon mode)" rejection path. Rule 12
  fail-loud: no more silent connection close on unknown args.

Tests cover: argv-sanitiser unit tests on bare/kv/two-arg forms,
goodbye-flush wire-bytes assertion via FlushTrackingWriter (NDX_DONE is
the last byte before FIN and at least one flush happened), and daemon
arg rejection unit tests on each batch family flag plus
recognised/positional regression guards.
@oferchen
oferchen merged commit 973cff4 into master Jun 11, 2026
18 of 19 checks passed
@oferchen
oferchen deleted the fix/uts-15-batch-mode-daemon-arg-defense branch June 11, 2026 03:10
oferchen added a commit that referenced this pull request Aug 24, 2026
…rg-defense

fix(daemon): strip batch flags + explicit goodbye flush + arg rejection error
oferchen added a commit that referenced this pull request Aug 24, 2026
UTS-9.REOPEN reported a silent connection close at byte ~612425 when an
oc-rsync client pulled a file from an oc-rsync daemon with -zz
(new-style compression). The torn capture had no @error frame: the
trailing NDX_DONE raced the transport FIN.

The daemon-pull -zz codepath flows through
GeneratorContext::run() (crates/transfer/src/generator/transfer/
orchestrator.rs), which terminates after handle_goodbye(). PR #5609
(UTS-15.c) added an explicit writer.flush() at that exit point to
fix the upstream batch-mode interop suite; the same flush also closes
the UTS-9 lineage because every daemon-sender role flows through the
same return path. This change closes the verification gap.

The regression test in crates/core/tests/uts_9_daemon_gzip_download_
goodbye.rs spawns an oc-rsync daemon serving a deterministic ~700 KB
file (sized to clear the 612425-byte cutoff), pulls it with
`oc-rsync -azz`, and asserts:

- exit 0
- stderr does not contain "connection unexpectedly closed"
- destination matches source byte-for-byte

The audit doc at docs/audits/uts-9-daemon-gzip-download-goodbye.md
captures the codepath analysis, the cross-check vs UTS-15.c batch-mode,
and the upstream io_flush(FULL_FLUSH) references at main.c:983 / 1344.

Refs UTS-9.REOPEN, companions PR #5609 (UTS-15.c).
oferchen added a commit that referenced this pull request Aug 24, 2026
…ye-flush coverage (UTS-9.REOPEN.1-3)

Audit bundle for UTS-9.REOPEN.1 (tcpdump capture command set),
UTS-9.REOPEN.2 (daemon-sender post-recv_files phase=3 goodbye path
trace), and UTS-9.REOPEN.3 (UTS-15.c goodbye-flush coverage analysis).

Findings:

- The 612425-byte cutoff is not a protocol constant. It is the byte at
  which the receiver sees a transport FIN with no orderly NDX_DONE
  having landed first, given the negotiated multiplex window and the
  test fixture size.
- The daemon-sender goodbye path flows through
  GeneratorContext::run() -> send_stats -> handle_goodbye and exits
  through the post-goodbye writer.flush() at orchestrator.rs:142.
- That post-goodbye flush is the same defense PR #5609 added for
  UTS-15.c batch-mode (~2241725-byte cutoff). The two regressions
  surfaced against different upstream tests but share an identical
  root cause: GeneratorContext::run() did not enforce upstream's
  io_flush(FULL_FLUSH) contract before returning.
- The UTS-9 lineage is therefore covered by PR #5609 plus the
  regression test shipped in commit e2adb07
  (crates/core/tests/uts_9_daemon_gzip_download_goodbye.rs) and the
  EDG-GOODBYE contract suite shipped in commit 9d7d061
  (crates/protocol/tests/goodbye_contract.rs).

Feed-forward:

- UTS-9.REOPEN.4: covered by PR #5609 - no additional production-code
  change needed.
- UTS-9.REOPEN.5: shipped regression test covers the -zz round-trip;
  natural extension is a -z (legacy zlib) cell on the same fixture.

The tcpdump command set is documented for the rsync-profile podman
container per the standing container-debug guidance. The capture is
documented as commands rather than committed as a pcap because the
cutoff byte varies by host TCP buffer sizes and the fix already
shipped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant