Skip to content

fix(daemon): symmetric safe_arg/unbackslash_arg for wildcards (UTS-8.REOPEN) - #5727

Merged
oferchen merged 1 commit into
masterfrom
fix/uts8-groupmap-wild-safe-arg
Jun 12, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/uts8-groupmap-wild-safe-arg

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Locks the round-trip parity between client-side safe_arg_for_daemon
and daemon-side unbackslash_arg for the option-arg escape set.
Mirrors upstream options.c:2539-2594 (safe_arg, rsync 3.4.4) and
io.c:1295-1306 (unbackslash_arg).

The asymmetric case is upstream issue #829: under non-protect_args
daemon mode a 3.4.3+ client wraps --groupmap=*:GID with
safe_arg("--groupmap", "*:GID") which backslash-escapes *. The
daemon must reverse the escape before option parsing or
--groupmap=\*:GID reaches parse_name_map() and the wildcard
silently mismatches.

The existing implementations of safe_arg_for_daemon (client) and
unbackslash_arg (daemon) are symmetric by construction:
unbackslash_arg collapses \X -> X for any X (mirroring
upstream's if (*f == '\\' && f[1]) f++; loop). This PR adds the
character-level tests that pin the contract so a future drift in
either escape set is caught at unit-test time instead of resurfacing
as daemon-groupmap-wild interop failure.

Changes

  • crates/core/.../arguments.rs: byte-for-byte pin
    safe_arg_for_daemon("--groupmap=*:42") == "--groupmap=\*:42"
    plus a full-set round-trip across
    WILD_CHARS + SHELL_CHARS (*?[]!#$&;|<>(){}\"' \t\`).
  • crates/daemon/.../tests.rs: ground-truth port of upstream
    safe_arg (option-arg branch) used to assert
    unbackslash_arg(safe_arg("--groupmap", value)) == value for the
    wildcard, every escape character, and the --usermap/--groupmap
    wildcard family.

The ground-truth safe_arg helper in the daemon test module is
independent of safe_arg_for_daemon so the contract is locked
against upstream wire output rather than against our own escape
code.

Test plan

  • cargo nextest run -p oc-rsync-daemon -E 'test(unbackslash)' green
  • cargo nextest run -p oc-rsync-core -E 'test(safe_arg)' green
  • cargo nextest run -p oc-rsync-core -E 'test(every_safe_arg_escape_char_round_trips_through_unbackslash)' green
  • daemon-groupmap-wild upstream runtest cell green in both
    default-args and secluded-args variants

@github-actions github-actions Bot added the bug Something isn't working label Jun 12, 2026
oferchen added a commit that referenced this pull request Jun 12, 2026
* chore: fix master fmt drift + filter_map_bool_then clippy lint

Master CI broke on rustfmt 1.88 and clippy 1.88:

1. `crates/cli/src/frontend/server/run.rs:244` - `use fast_io::landlock::{...}`
   collapses to a single line under rustfmt 1.88 (introduced by PR #5724's
   landlock wire-in).
2. `crates/transfer/src/generator/filters.rs:589` - `let split = ...` long-form
   collapses to single-line under rustfmt 1.88.
3. `crates/transfer/src/generator/file_list/mod.rs:267` - rewrite
   `filter_map(|(b, rel)| (b == &entry.base).then(|| rel.clone()))` as the
   equivalent `filter(...).map(...)` pair so clippy 1.88's new
   `filter_map_bool_then` lint stays clean. Behaviour-identical.

Unblocks PRs #5725, #5726, #5727 once they rebase onto this.

* fix: drop extraneous deref in filter predicate

In .filter(), the destructured 'b' is already &PathBuf since iter() yields
&(PathBuf, PathBuf) and filter receives &Self::Item. The extra deref made it
PathBuf, causing E0277 'can't compare PathBuf with &PathBuf'.

* chore(cli): inline format args in --partial-dir test (clippy 1.88)

uninlined_format_args lint denies the build under clippy 1.88.
…REOPEN)

Lock the round-trip parity between the client-side option-arg escape
emitted by `safe_arg_for_daemon` and the daemon-side `unbackslash_arg`
un-escape. Mirrors upstream `options.c:2539-2594` (rsync 3.4.4
`safe_arg`) and `io.c:1295-1306` (`unbackslash_arg`).

The asymmetric case is `--groupmap=*:GID` (upstream issue #829): a
3.4.3+ non-protect_args client wraps the value with
`safe_arg("--groupmap", value)`, which backslash-escapes `*` because
it is a member of `WILD_CHARS`. The daemon must reverse the escape
before option parsing or `--groupmap=\*:GID` reaches
`parse_name_map()` and the wildcard silently mismatches.

The existing implementation is already symmetric, but had no
character-level coverage of the escape set. Adds:

- `crates/core/.../arguments.rs`: pin the byte-for-byte form
  `safe_arg_for_daemon("--groupmap=*:42") == "--groupmap=\*:42"`,
  plus a round-trip test that covers every `WILD_CHARS + SHELL_CHARS`
  escape character (`*?[]!#$&;|<>(){}\"'` \t\\`).
- `crates/daemon/.../tests.rs`: ground-truth port of upstream
  `safe_arg` (option-arg branch) used to assert that
  `unbackslash_arg(upstream_safe_arg("--groupmap", value)) == value`
  for the wildcard, every escape character, and the
  `--usermap`/`--groupmap` wildcard family.

The ground-truth `safe_arg` helper in the daemon test module is
independent of the oc-rsync `safe_arg_for_daemon` implementation so
the contract is locked against upstream wire output rather than
against our own escape code.

No behaviour change; defense-in-depth coverage that pins the daemon
arg backslash contract against URV-2.a regression. Production
non-protect_args round-trip remains exercised by the
secluded-args-default code path that already covers the wire layer.

upstream: options.c:2539-2594 safe_arg() (client-side escape)
upstream: io.c:1295-1306 unbackslash_arg() (daemon-side un-escape)
upstream: options.c:2912-2916 safe_arg("--usermap"|"--groupmap", value)
@oferchen
oferchen force-pushed the fix/uts8-groupmap-wild-safe-arg branch from 212d13d to 00f4d00 Compare June 12, 2026 01:40
@oferchen
oferchen merged commit e9b32d3 into master Jun 12, 2026
56 of 69 checks passed
@oferchen
oferchen deleted the fix/uts8-groupmap-wild-safe-arg branch June 12, 2026 14:39
oferchen added a commit that referenced this pull request Aug 24, 2026
* chore: fix master fmt drift + filter_map_bool_then clippy lint

Master CI broke on rustfmt 1.88 and clippy 1.88:

1. `crates/cli/src/frontend/server/run.rs:244` - `use fast_io::landlock::{...}`
   collapses to a single line under rustfmt 1.88 (introduced by PR #5724's
   landlock wire-in).
2. `crates/transfer/src/generator/filters.rs:589` - `let split = ...` long-form
   collapses to single-line under rustfmt 1.88.
3. `crates/transfer/src/generator/file_list/mod.rs:267` - rewrite
   `filter_map(|(b, rel)| (b == &entry.base).then(|| rel.clone()))` as the
   equivalent `filter(...).map(...)` pair so clippy 1.88's new
   `filter_map_bool_then` lint stays clean. Behaviour-identical.

Unblocks PRs #5725, #5726, #5727 once they rebase onto this.

* fix: drop extraneous deref in filter predicate

In .filter(), the destructured 'b' is already &PathBuf since iter() yields
&(PathBuf, PathBuf) and filter receives &Self::Item. The extra deref made it
PathBuf, causing E0277 'can't compare PathBuf with &PathBuf'.

* chore(cli): inline format args in --partial-dir test (clippy 1.88)

uninlined_format_args lint denies the build under clippy 1.88.
oferchen added a commit that referenced this pull request Aug 24, 2026
…REOPEN) (#5727)

Lock the round-trip parity between the client-side option-arg escape
emitted by `safe_arg_for_daemon` and the daemon-side `unbackslash_arg`
un-escape. Mirrors upstream `options.c:2539-2594` (rsync 3.4.4
`safe_arg`) and `io.c:1295-1306` (`unbackslash_arg`).

The asymmetric case is `--groupmap=*:GID` (upstream issue #829): a
3.4.3+ non-protect_args client wraps the value with
`safe_arg("--groupmap", value)`, which backslash-escapes `*` because
it is a member of `WILD_CHARS`. The daemon must reverse the escape
before option parsing or `--groupmap=\*:GID` reaches
`parse_name_map()` and the wildcard silently mismatches.

The existing implementation is already symmetric, but had no
character-level coverage of the escape set. Adds:

- `crates/core/.../arguments.rs`: pin the byte-for-byte form
  `safe_arg_for_daemon("--groupmap=*:42") == "--groupmap=\*:42"`,
  plus a round-trip test that covers every `WILD_CHARS + SHELL_CHARS`
  escape character (`*?[]!#$&;|<>(){}\"'` \t\\`).
- `crates/daemon/.../tests.rs`: ground-truth port of upstream
  `safe_arg` (option-arg branch) used to assert that
  `unbackslash_arg(upstream_safe_arg("--groupmap", value)) == value`
  for the wildcard, every escape character, and the
  `--usermap`/`--groupmap` wildcard family.

The ground-truth `safe_arg` helper in the daemon test module is
independent of the oc-rsync `safe_arg_for_daemon` implementation so
the contract is locked against upstream wire output rather than
against our own escape code.

No behaviour change; defense-in-depth coverage that pins the daemon
arg backslash contract against URV-2.a regression. Production
non-protect_args round-trip remains exercised by the
secluded-args-default code path that already covers the wire layer.

upstream: options.c:2539-2594 safe_arg() (client-side escape)
upstream: io.c:1295-1306 unbackslash_arg() (daemon-side un-escape)
upstream: options.c:2912-2916 safe_arg("--usermap"|"--groupmap", value)
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