Skip to content

fix: send the daemon -s argv split the way server_options() does - #8880

Merged
oferchen merged 1 commit into
masterfrom
fix/client-iconv-protect-args-argv
Nov 27, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/client-iconv-protect-args-argv

Conversation

@oferchen

Copy link
Copy Markdown
Owner

What rsync 3.5.2 does

Under -s, server_options() builds --server, --sender (on a pull), the compact flag string with s as its first letter (options.c:2858-2859) and --iconv=... (options.c:2975-2983), then inserts a NULL (options.c:2985-2986). start_inband_exchange() sends the args before that NULL in the first pass (clientserver.c:443-450). send_protected_args() then sends rsync and only the args after the NULL (rsync.c:284-296).

A daemon client runs setup_iconv() before server_options() (clientserver.c:171-172 for a socket, main.c:678-679 before start_inband_exchange() over a remote shell). rsync.c:119-123 truncates iconv_opt at the comma there, so the daemon is sent the local charset. A remote-shell server is different: main.c:624 runs server_options() before setup_iconv(), so it gets the post-comma half. oc already sends that correctly.

Why the 3.5.2 daemon read the list unconverted

I captured the daemon's stdin with strace (--iconv=UTF-8,ISO-8859-1 -s --files-from=list, module charset = ISO-8859-1):

3.5.2 client: --server\0--sender\0-srRe.iLsfxCIvu\0--iconv=UTF-8\0\0 rsync\0--files-from=-\0--from0\0.\0src/\0\0
oc client:    --server\0--sender\0--secluded-args\0--iconv=ISO-8859-1\0\0 rsync\0--server\0--sender\0-rRe.iLsfxCIvu\0--files-from=-\0--from0\0.\0src/\0\0

oc's second pass repeated --server. The daemon's second parse_arguments() handles OPT_SERVER and sets iconv_opt = NULL (options.c:1535-1547). rsync_module() then sees no iconv_opt and closes the ic_send/ic_recv converters that came from the module charset (clientserver.c:1279-1289). With no converters, filesfrom_convert stays 0 (compat.c:820-826). The daemon sender looked up the raw UTF-8 name and failed with link_stat "caf\#303\#251" (in src) failed, which gives exit 23.

The --iconv value itself does not matter on the daemon, because its converters come only from the module charset (clientserver.c:763-768). Only the repeated --server breaks the transfer.

The fix

Daemon client argv only (orchestration/arguments.rs):

  • The flag string carries s under -s, and --iconv= follows it directly, as in upstream.
  • The first pass is the upstream prefix: --server, --sender on a pull, the flag string and --iconv. The protected args are rsync plus everything after it. Nothing from the first pass is repeated.
  • --iconv= forwards the local charset (the pre-comma half).
  • --checksum-choice moves from before the flag string to after --suffix, its upstream position (options.c:3052-3056). It has to move out of the first-pass prefix.
  • build_minimal_daemon_args (the old --secluded-args first pass) is removed.

The remote-shell argv already matched 3.5.2 for both pull and push (captured: --server [--sender] -srRe.iLsfxCIvu --iconv=ISO-8859-1, then rsync ... . path). It is unchanged.

Measured (oc client, rsync 3.5.2 daemon over a remote shell, module charset ISO-8859-1)

client -s daemon argv after the fix exit copied
rsync 3.5.2 yes -srRe.iLsfxCIvu --iconv=UTF-8 / rsync --files-from=- --from0 . src/ 0 café
oc before yes --secluded-args --iconv=ISO-8859-1 / rsync --server --sender -rRe... ... 23 nothing
oc after yes byte-identical to 3.5.2 (strace) 0 café
rsync 3.5.2 no -rRe.iLsfxCIvu --iconv=UTF-8 --files-from=- --from0 . src/ 23 nothing
oc before no -rRe... --files-from=- --from0 --iconv=ISO-8859-1 . src/ 23 nothing
oc after no byte-identical to 3.5.2 (strace) 23 nothing

Tests

  • crates/cli/tests/files_from_iconv_protect_args.rs: the skip of the oc client to rsync 3.5.2 daemon pairing under -s is removed, so a_daemon_pull_with_protect_args_converts_the_list now covers it. a_daemon_pull_without_protect_args_sends_the_list_unconverted covers the case without -s.
  • orchestration/tests.rs: four wire tests check the bytes sent for each pass: a protected pull's first pass (flag string with s, local --iconv), a protected pull's second pass (rsync . test/ only), a protected push without iconv, and an unprotected pull with --iconv right after the flag string.
  • Mutation: reverting arguments.rs to the base makes all 4 new unit tests fail, and makes a_daemon_pull_with_protect_args_converts_the_list fail in the oc client to rsync 3.5.2 daemon pairing (exit 23, nothing copied, where 3.5.2 gives exit 0 and café). With the fix all 8 cells pass with OC_RSYNC_UPSTREAM_COMPAT=1, and the daemon module_access tests pass (342).

Remaining differences (separate issues)

  • Sender diagnostics print a non-UTF-8 name lossily (caf\357\277\275 where 3.5.2 prints caf\#351).
  • An invalid UTF-8 name on a push gives [receiver] cannot convert filename plus extra delete_file / could not make way lines. 3.5.2 prints [sender] cannot convert filename.
  • The oc daemon still accepts the old oc-client first pass (--secluded-args), so older oc clients keep working.

Closes #8877

Under -s an oc client sent "--secluded-args --iconv=REMOTE" in the first
pass and repeated --server, --sender and the flag string in the protected
args. An rsync 3.5.2 daemon parses that second --server, which clears
iconv_opt (options.c:1535-1547), so rsync_module() closes the module
charset converters (clientserver.c:1279-1289). filesfrom_convert then
stays 0 (compat.c:820-826) and a forwarded --files-from list is looked
up unconverted, exiting 23.

The first pass is now what server_options() puts before its NULL
(options.c:2850-2986): --server, --sender on a pull, the flag string
with s first, and --iconv. The protected args are "rsync" plus only
what follows (rsync.c:284-296). The daemon is sent the local charset,
because a daemon client runs setup_iconv() before server_options()
(clientserver.c:171-172, main.c:678-679) and rsync.c:119-123 truncates
iconv_opt at the comma. --checksum-choice moves to its upstream place
after --suffix (options.c:3052-3056). The remote-shell argv already
matched and is unchanged.
@oferchen oferchen added this to the v0.6.5 milestone Nov 27, 2026
@github-actions github-actions Bot added the bug Something isn't working label Nov 27, 2026
@oferchen
oferchen merged commit feef1cc into master Nov 27, 2026
90 checks passed
@oferchen
oferchen deleted the fix/client-iconv-protect-args-argv branch November 27, 2026 09:48
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.

oc client -s --iconv pull from an rsync 3.5.2 daemon exits 23

1 participant