Skip to content

fix: parse the server argv like 3.5.1, including filter options - #8343

Closed
oferchen wants to merge 6 commits into
masterfrom
fix/server-remote-option-hang
Closed

oferchen wants to merge 6 commits into
masterfrom
fix/server-remote-option-hang

Conversation

@oferchen

@oferchen oferchen commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

When an oc server's own argv carries a remote option, it now ignores it as 3.5.1 does. Before this change the server hung, and so did the client. This happens with --rsync-path="oc-rsync -M--fake-super", for example.

Root cause

Measured with strace on the server:

  1. detect_secluded_args_flag treated any s in a single-dash token as -s. The s inside -M--fake-super therefore turned on secluded-args mode.
  2. recv_secluded_args then read the client's protocol version (!\0\0) as an argument list.
  3. The server discarded that list and continued with its command line. It started the handshake with 3 of the client's 4 version bytes already consumed, so it blocked forever, and the client waited for it.

A stray -s on the server argv reaches the same hang by a second route. 3.5.1 exits 1 there: read_args() replaces argv, and with no operands left it hits usage(FERROR); exit_cleanup(RERR_SYNTAX) (main.c:1956-1969).

A mismatch in the -e capability letters alone does not hang either implementation. A 3.5.1 client pushing to either server with the letters stripped (-r) or empty (-re.) completes the transfer.

Changes

  1. fix: ignore -M on the server argv and refuse an empty secluded list
    • strip_remote_options removes -M<v>, -M <v>, --remote-option=<v> and --remote-option <v> before any server scanner sees the argv. A server only records these (options.c:1762-1777); only a local copy's forked server re-parses them (pipe.c:143-150).
    • A value without a leading dash is refused with 3.5.1's Remote option must start with a dash: <v> and exit 1 (options.c:1764-1767).
    • In secluded mode, a received list with nothing after its arg0 prints usage and exits 1 (RERR_SYNTAX), as main.c:1956-1969 does.
  2. fix: read the secluded-args flag from a short-option cluster like popt
    • detect_secluded_args_flag now scans a short-option cluster the way popt does. It reads letters up to the first option that takes a value: @ B M T e f, the only short options with POPT_ARG_STRING/POPT_ARG_INT in options.c long_options.
    • So -fs, -T/tmp/s, -B1s and -rM--fake-super no longer turn on secluded args.
    • Stopping at e covers what the old split at . was guarding against: the s among the capability letters.

Evidence

  • New test tests/server_remote_option_argv.rs.
    • Every push runs under run_deadlined with a 30 s budget, so a hang fails as a named TIMEOUT.
    • Each case runs with the oc client, and with the 3.5.1 client when the oracle is installed.
    • Cases:
      • All four -M spellings transfer, and the value never takes effect: no user.rsync.* stash appears on the destination.
      • -Mfoo is refused with the dash message and transfers nothing.
      • A stray -s fails with syntax or usage error (code 1).
  • 3.5.1 side by side, in the same push matrix:
    • -M--fake-super and --remote-option=--fake-super: both servers exit 0 and transfer.
    • -s: both exit 12 at the client, and the server reports syntax or usage error (code 1).
    • -Mfoo: both exit 12 at the client, with Remote option must start with a dash: foo.
  • New unit test detect_secluded_args_ignores_s_in_an_option_value.
  • Mutations, each caught:
    • No stripping: the remote-option tests fail.
    • No empty-list refusal: the stray -s test fails as TIMEOUT ... after 30s.
    • No dash check: the -Mfoo test fails.
    • Keep the split form's value token: the "value never takes effect" assertion fails.
  • Gates:
    • check_rustfmt_all OK.
    • Workspace clippy OK; windows-gnu clippy (cli) OK; no-default cli clippy OK.
    • dead_code_census OK; citation ratchet OK.
    • Targeted nextest (cli server and secluded tests, the new binary): 303/303, on the rebased head.

Whole-argv parse (task 291, third commit)

  1. fix: parse the whole server argv like 3.5.1 popt pass
    • normalize_server_argv replaces strip_remote_options. It reads every token before -- the way 3.5.1's single popt pass does (options.c:1497), so a short option counts wherever it sits, before --server included.
    • Each cluster is read up to its first value-taking letter (@ B M T e f). Every letter joins one flag string placed right after --server, with the last -e value kept. -B, -@ and -T become the -B<n>, -@<n> and --temp-dir= forms the long-option pass already reads. -M and --remote-option are still dropped, with the dash check above. -f is consumed at one marked point and not applied yet; server-argv filters are a follow-up.
    • The first --server restarts the popt pass from argv[1] (options.c:1517-1524), so an option ahead of it is parsed twice. A -v there counts as -vv, and both servers then print delta-transmission enabled.
    • An unknown short or long option is refused as 3.5.1 refuses it: <prog>: <opt>: unknown option, then the RERR_SYNTAX trailer (options.c:915, main.c:1909-1912). The on remote machine: prefix (options.c:2051-2054) and the [server=...] role apply only once --server has been parsed, because that option sets am_server (options.c:889). Ahead of it, the line has no prefix and the role is [client=...].
    • A secluded-args list goes through the same rewrite after it is merged, as main.c:1959-1960 feeds it to the same popt pass. The rewrite is the identity on an upstream server argv, so running it twice is safe.

Evidence for this commit:

  • New test tests/server_argv_popt_parity.rs. Every push is driven by the 3.5.1 client under a 30 s deadline that fails as TIMEOUT.
    • -v ahead of --server: the 3.5.1 and oc servers both exit 0, transfer the file, and print delta-transmission enabled.
    • -j before --server, -vj after it, --bogus before and --bogus after: oc's exit code and refusal lines (text and role) equal 3.5.1's in each case, and nothing is transferred.
  • Unit tests for the rewrite: clusters on both sides of --server, value options taking the rest of the token or the next one, identity on an upstream argv, refusal text and side, and operands after -- left alone.
  • Mutations, each caught:
    • No double count ahead of --server: the -v cell fails.
    • Unknown letters accepted: the refusal cell fails.
    • Long-option refusal always attributed to the server: the refusal cell fails.
    • Clusters ahead of --server left unmerged: 4 cells fail, including two in server_remote_option_argv.rs.
  • Gates on the folded head: check_rustfmt_all OK; workspace, windows-gnu (cli) and no-default (cli) clippy OK; dead_code_census OK; citation ratchet OK; targeted nextest 315/315.

The two gaps this PR listed as task 291 are closed: a stray option before the flag string is honoured, and -rM--x merges into the flag string as -r. A refused -M value ahead of --server now prints the cause and a [client=...] trailer on two lines, as 3.5.1 does.

Server-argv filters (task 617, commits 4-6)

Filter options on a server's own argv now work as they do in 3.5.1.

  • Remote-shell server. It applies -f, -F, --filter, --exclude, --include, --exclude-from and --include-from from its argv, ahead of the rules the client sends on the filter list. Before this change it ignored -f and refused the long forms as unknown options (rc 12).
  • Daemon. It reads -M-forwarded filter options through the same argv pass. A filter inside a short cluster (-M-rf- x) was previously missed.

What 3.5.1 does:

  • parse_arguments() adds argv filters to filter_list, in argv order (options.c:1620-1656). -F adds : /.rsync-filter, then - .rsync-filter (options.c:1718-1727). recv_filter_list() then appends the wire rules (exclude.c:1971-1986).
  • The server parses its argv with the client's own code. Files are opened relative to its cwd and are not sanitized; only a daemon module sets sanitize_paths (clientserver.c:1068).
  • The first --server restarts the popt pass (options.c:1517-1524) without clearing filter_list or F_option_cnt. A filter option ahead of --server therefore applies twice, so one -F there counts as -FF.
  • A file that fails to open is reported by rsyserr() as rsync: [server] failed to open exclude file X: ... (2), followed by the RERR_FILEIO trailer (exclude.c:1714-1719). A malformed rule prints filter_rule_err()'s bare line, followed by the RERR_SYNTAX trailer (exclude.c:132-136).
  1. refactor: split the argv filter rule builder out of apply_filters
    • build_filter_rules is the client's argv rule loop with no ClientConfigBuilder in its signature. apply_filters wraps it, so client behaviour is unchanged; the existing cli filter tests pass untouched.
  2. fix: honour filter options on a remote-shell server argv like 3.5.1
    • normalize_server_argv turns every filter option into a joined --opt=VALUE token behind the flag string, in argv order:
      • -f and the split --exclude VALUE forms are joined to their values.
      • Each -F is expanded to its rule.
      • Options ahead of --server are kept twice.
    • The new server/argv_filters.rs turns those tokens into the client's FilterOrderTokens. It builds the rules with build_filter_rules and converts them with the client's build_wire_format_rules, which core now exports. The result goes into the existing ServerConfig::argv_filter_rules, which already ranks those rules ahead of the received list.
    • A failure prints upstream's line and a [server=...] trailer and exits with upstream's code.
  3. fix: read daemon -M filter options through the shared argv pass
    • normalize_server_argv and its helpers move from the cli server into transfer::server_argv (core::server::server_argv), so the daemon can call it. The cli re-exports them, and the unit tests move with them.
    • The daemon's argv filter collector now reads the normalized options. Its own -f/-F token arms are gone, now that every filter option arrives joined. The module-confined reader, the daemon-rule gating and the refusals are unchanged; the existing daemon_m_forwarded_filters tests pass untouched.

Evidence for these commits:

  • New tests/server_argv_filters.rs. Each cell asserts 3.5.1's own outcome first, so a cell cannot pass vacuously, then checks that oc matches it. The 3.5.1 client drives every transfer under a 30 s deadline, so a hang fails as a named TIMEOUT.
    • Pull with --exclude=b, --exclude b (both after --server) and -f '- b' (before it): d/b is dropped.
    • Pull with -F after --server: the per-directory .rsync-filter (- a) applies. With -F before --server, it also hides .rsync-filter itself.
    • Pull with --exclude-from=nope: exit 12 at the client. The server lines match: rsync: [server] failed to open exclude file nope: No such file or directory (2) and the error in file IO (code 11) trailer.
    • --delete push with -f 'P keep': keep survives, as on 3.5.1.
    • Daemon --delete push with -M-rf- x, compared against a 3.5.1 daemon: x survives.
  • Unit tests in transfer::server_argv: filter options joined in argv order, doubled ahead of --server, a third -F adding nothing, and the rewrite applied a second time leaving the argv unchanged.
  • Mutations, each caught:
    • Argv rules never reach the config: 3 cells fail.
    • No doubling ahead of --server: the -F cell fails.
    • -F not expanded: the -F cell fails.
    • Open failure printed like a rule error: the --exclude-from cell fails.
    • Split --exclude VALUE not joined: the pull cell fails.
    • Daemon collector reading raw tokens: the daemon cell fails.
  • Gates: check_rustfmt_all OK; workspace clippy OK; windows-gnu clippy (cli, daemon, transfer) OK; no-default clippy (cli, transfer, daemon, core) OK; dead_code_census OK; citation ratchet OK; targeted nextest (cli, bin, transfer, daemon: server, filter, secluded, remote-option and the new binaries) 1192/1192.

Not in scope

  • At -vv and above, the two servers print different debug lines (3.5.1 prints protocol and server_recv lines, oc prints others). That is server debug-line parity, not argv parsing.
  • --delete-excluded given on the server argv does not mark argv rules sender-side the way exclude.c:1478-1481 does for rules parsed after it. The server builds its argv rules as though --delete-excluded were absent.
  • An argv that the popt pass refuses (an unknown short letter) is read by the daemon filter collector as sent. Whether the oc daemon refuses such an argv the way 3.5.1's parse_arguments() does is a separate question.
  • A merge file that fails to open (-f '. nope') is reported with its absolute path where 3.5.1 prints the name as given. The oc client does the same today; the server inherits it from the shared builder.

@oferchen
oferchen force-pushed the fix/server-remote-option-hang branch from 17e14dd to b2295f5 Compare November 10, 2026 14:33
@oferchen oferchen changed the title fix: ignore -M on the server argv instead of hanging fix: parse the server argv like 3.5.1 and stop the -M hang Nov 10, 2026
@oferchen oferchen closed this Nov 10, 2026
@oferchen oferchen reopened this Nov 10, 2026
@oferchen oferchen changed the title fix: parse the server argv like 3.5.1 and stop the -M hang fix: parse the server argv like 3.5.1, including filter options Nov 10, 2026
@oferchen oferchen closed this Nov 10, 2026
@oferchen oferchen reopened this Nov 10, 2026
@oferchen
oferchen force-pushed the fix/server-remote-option-hang branch 2 times, most recently from d5a8a8f to 6918635 Compare November 10, 2026 19:06
@oferchen
oferchen force-pushed the fix/server-remote-option-hang branch 5 times, most recently from e2cd45d to 1819b44 Compare November 11, 2026 10:32
@oferchen
oferchen force-pushed the fix/server-remote-option-hang branch from 1819b44 to eabfba3 Compare November 11, 2026 10:49
@oferchen
oferchen force-pushed the fix/server-remote-option-hang branch from eabfba3 to 571068d Compare November 11, 2026 10:55
@oferchen

Copy link
Copy Markdown
Owner Author

Merge train: this pull request failed its batch run on its own (https://github.com/oferchen/rsync/actions/runs/43029669131). Failed required checks: upstream-testsuite / upstream testsuite, . It is held out of batches until its head changes.

oferchen added a commit that referenced this pull request Nov 11, 2026
)

## Summary

Collapses the daemon's module filter parser into the one core filter
parser, so module directives, client options and server argv options all
go through a port of 3.5.1's `parse_filter_str` (exclude.c:1516-1598)
and `add_rule` (exclude.c:279-314). Stacked on #8343.

- **One parser.** `crates/core/src/client/filter_args/filter_str.rs`
carries the rule template and xflags (`OLD_PREFIXES`, `ABS_IF_SLASH`,
`DIR2WILD3`). `add_rule` does the side drop, the slash anchoring (a
trailing slash does not count, leading `**` stays unanchored) and the
`/***` suffix on Exclude and Protect rules only. `--include`,
`--exclude` and `--filter` use it, and so do the module directives.
- **Module directives** (`clientserver.c:933-952`): `filter` is
word-split with the full grammar; `include`/`exclude` are word-split
with `OLD_PREFIXES`; `include from`/`exclude from` read with
`OLD_PREFIXES` and `FATAL_ERRORS`. About 1,700 lines of the daemon's own
parser in `module_access/helpers.rs` are deleted. The old parser ignored
`!` and anchored `/`, so a module served files that 3.5.1 hides.
- **A clear empties the whole list.** `pop_filter_list(listp);
listp->head = NULL` (exclude.c:1540-1546) drops every rule ahead of the
clear, argv rules included. oc used to clear only the file's own rules.
This was MEASURED on 3.5.1: with `-f '- b' -f '. rules'` and `!` in
`rules`, both a and b transfer.
- **Refusal (E1).** A refused module directive ends the session before
`@RSYNCD: OK`, and the cause goes to the daemon log only, as 3.5.1 does.
oc used to send an `@ERROR` line it made up itself.
- **Merge-file opens** are gated by `check_filter(&daemon_filter_list)`
while the list is being built (exclude.c:1639-1664). An absolute name
skips `module_dirlen` by length alone. A name with no slash opens from
cwd (`parse_merge_name`, exclude.c:704-715).
- **Error text.**
  - A rule read from a file is reported as `<rule from FILE line N>`.
- A word-split file rule is reported as `<rule from FILE>`
(exclude.c:71-136, MEASURED).
  - `-from` records now carry their line number.
- **Wire fixes.**
- A `:p` dir-merge rule now sends `p` on the wire (`get_rule_prefix`,
exclude.c:1872).
  - A `:r` dir-merge rule keeps its side.
- The receiver's daemon filter set honours `directory_only`, `anchored`
and `negate`.
- Corrected the `pop_filter_list` comment in merge.rs, which described
the clear wrongly.

## Tests

- New `tests/daemon_module_filters.rs`: 7 cells against live 3.5.1.
  - negate and abs-path modifiers
  - both-sides versus sender-only rules
  - a trailing slash does not anchor
  - old-prefix word split
  - a clear inside a merge file
  - a self-excluding merge gates its own open
  - a refused directive is logged and sends nothing
- New cell `a_clear_inside_a_file_empties_the_rules_ahead_of_it` in
`crates/cli/tests/upstream_compat_filter_rule_parse.rs`.
- New `crates/core/src/client/filter_args/tests/filter_str.rs`: the
`add_rule` cells, plus the 17 split cells moved from the daemon.

### Dropped or replaced daemon tests

The parser these tests exercised is deleted:

- `strip_matched_keyword_*` (7): the helper is gone. The keyword walk is
covered by the core `split_*` cells.
-
`build_pattern_rule_{exclude,include,anchored,doublestar_prefix_stays_unanchored,directory_only_exclude_dir2wild3,directory_only_include_preserved}`,
`pattern_{leading_slash_is_anchored,no_slash_is_not_anchored,embedded_slash_is_anchored,deep_path_is_anchored}`,
`directory_exclude_gets_wild3`,
`directory_include_keeps_directory_flag`,
`include_with_embedded_slash_is_anchored` (13): duplicates of the core
`add_rule` cells (`a_pattern_without_a_slash_is_added_as_written`,
`a_slash_anywhere_in_the_pattern_anchors_it`,
`a_leading_double_star_stays_unanchored`,
`a_trailing_slash_marks_a_directory_rule_and_is_not_counted`).
- `an_inexpressible_modifier_drops_the_rule_rather_than_refusing_it`:
replaced by `the_negate_and_xattr_modifiers_are_carried_on_the_rule`.
The rule is now carried, not dropped.
- `read_patterns_from_file_reads_a_plain_file_unchanged`: a duplicate of
`exclude_from_reads_one_pattern_per_line`.
- The other `read_patterns_from_file_*` and `split_filter_tokens_*`
tests were renamed to `exclude_from_*` and moved to core `split_*`,
unchanged.
- Updated tests:
- `build_daemon_filter_rules_line_final_clear_*` now expects an empty
list.
  - `*_non_merge_cvs_*` now expects the `-C` defaults expanded.
  - Three cli tests were renamed to `*_clears_*`.

## Residuals

- **E2 (task 547).** These three rows of the 3.5.1 differential table
still disagree: `:w .ws` on rsh, on daemon `-M` and on a module
directive. All three are the sender-side per-dir merge error report:
3.5.1's client prints the parse error first and exits 1. The 4 Push
cells in `upstream_compat_filter_rule_parse`
(`c_modifier_inside_a_per_directory_merge_file`,
`merge_file_rules_end_where_upstream_ends_them`,
`naming_both_sides_still_names_a_side`,
`sided_merge_file_refuses_a_sided_rule`) fail for the same reason. They
also fail on master's binary under `OC_RSYNC_UPSTREAM_COMPAT=1` and SKIP
in CI. Task 547 fixes them in a PR stacked on this one.
- The missing filter-file texts `failed to read filter file '...'` and
`failed to read filter patterns from standard input` are not 3.5.1's.
This PR moved them unchanged from cli to core, and they are left for the
task 632 and 626 sweep.

## Gates

- `cargo fmt --check` and `check_rustfmt_all.py`
- workspace clippy `-D warnings`
- windows-gnu clippy (cli, daemon, transfer, core)
- no-default clippy (cli, transfer, daemon, core)
- dead-code census: one stale allowlist row (`with_dir_merge_options`)
removed
- citation ratchet: OK; cli baseline lowered from 1 to 0
- targeted nextest: 1839 run, 1835 pass. The 4 failures are the task 547
Push cells listed above.
@oferchen oferchen closed this Nov 12, 2026
@oferchen oferchen reopened this Nov 12, 2026
@oferchen

Copy link
Copy Markdown
Owner Author

Superseded by origin/master (#8383, #8384): all server argv normalization, filter option parsing, and parity tests are already on master with updated 3.5.2 citations.

@oferchen oferchen closed this Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant