Repository navigation
fix: escape control bytes in client stderr diagnostics - #8892
Merged
Merged
Conversation
rsync 3.5.2 passes every diagnostic line through filtered_fwrite() before it reaches the terminal. A client without -8 first checks the line against the locale codeset via ic_chck (rsync.c:96-98, log.c:463-496, filtered_fwrite(.., 0, ..) at log.c:476). A -8 client or a server calls filtered_fwrite(.., !allow_8bit_chars, ..) at log.c:499. filtered_char_len() escapes C0 except tab, DEL, 0x80-0x9f and a literal \#ddd as \#ooo (log.c:288-291). A refused filter rule is echoed through rprintf(FERROR) (exclude.c:133-136, exclude.c:1376), so a VT in the rule prints as \#13. oc printed these client lines raw: filter refusals, messages written through the client stderr MessageSink, the pre-formatted cause lines of a client error report, and the local-copy link_stat and vanished operand lines. The client stderr MessageSink now escapes with the process terminal style, reusing logging::escape. A message with nothing to escape keeps the copy-free vectored render. write_refusal takes the escape style. The daemon passes passthrough, because its log sink already escapes each line once, as logit() does (log.c:143).
rsync 3.5.2 prints "Unexpected local arg: %s" and the colon hint with two rprintf(FERROR, ...) calls (main.c:1591-1592). rwrite() keeps only each call's trailing newline raw (log.c:460) and escapes a newline inside the text as \#12 (log.c:288-291). oc built one cause with an embedded newline, so the new terminal escaping folded the two lines into one. A ClientError cause now holds one line per upstream call, and the report writes each through the escaper. clap's multi-line parse error is written line by line in the same way. The unknown-option refusal and the failed --log-file open line now go through the escaper too, as option_error() prints the token with rprintf (options.c:933).
A daemon that sends free text and then closes before acknowledging a module listing was reported as one message, with the received lines joined by newlines. The terminal escaping then printed them as \#12. rsync 3.5.2 prints each line it receives with its own rprintf() (clientserver.c:428-429 for @error, 438-439 for MOTD and listing lines). The refusal now carries the received lines as cause lines. The listing report writes each one through the escaper, then the existing "daemon refused module listing" trailer. The connect-failure lines on that path go through the escaper too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What rsync 3.5.2 does
rwrite()hands every FERROR/FWARNING/FINFO line tofiltered_fwrite()before it reaches the terminal:-8opensic_chck = iconv_open(cs, cs)(rsync.c:96-98).rwrite()then validates the line in the locale codeset (log.c:463-496). Each rejected byte is written as\#ooo(log.c:487), and the valid characters go throughfiltered_fwrite(f, convbuf, len, 0, ..)(log.c:476).-8client or a server takesfiltered_fwrite(f, buf, len, !allow_8bit_chars, ..)(log.c:499).filtered_char_len()(log.c:276-293) escapes C0 except TAB, DEL, 0x80-0x9F, and the backslash of a literal\#ddd(log.c:288-291). Withuse_isprintit also escapes every byteisprint()rejects.rwrite()peels one trailing newline and writes it raw (log.c:460).rprintf(FERROR, ...):filter_rule_err()at exclude.c:133-136 and theinvalid modifierline at exclude.c:1376. So a VT in the rule prints as\#013, both in the'%c'detail and in the echoed rule.What oc did
oc's daemon log file already escaped its lines (
LogFileWriter, mirroringlogit()at log.c:143), and so did lines forwarded from a server in MSG frames. Lines the client printed itself were not escaped:--filterrule (write_refusal).Messagewritten through the client stderrMessageSink.ClientErrorreport.link_stat ... failed/file has vanishedoperand lines, which the engine printed witheprintln!.The fix
It reuses the existing escaper in
logging::escape. There is no second escaper.logging::escape:may_need_escaping()is the fast-path testescape_for_outputalready ran, now split out so sinks can skip the copy.write_terminal_line()/eprint_terminal_line()write one escaped stderr line. A clean line goes out with no copy.MessageSink:terminal_escapingflag, set on the client stderr sink. A message whose text is clean keeps the vectored, allocation-free render. Only a text with something to escape is rendered into a buffer and escaped once.write_escaped_line()for pre-formatted lines.-8and the locale are parsed after the sink is built.write_refusaltakes anEscapeStyle:terminal_style(), as log.c:499 applies on a server before multiplexing.passthrough(). This is deliberate. The daemon's refusal lines also go to its log sink, which escapes on its own as upstream'slogit()does (log.c:143). Escaping here as well would print\#134#013, so each line is still escaped exactly once.emit_error_reportsends its cause and program lines throughwrite_escaped_line. The remote shell's own stderr is still written as received.Measured on Linux, stderr cause line (
od -c) and exit code--filter=$'+\vfoo'invalid modifier '\#013' at position 1 in filter rule: +\#013foo, exit 1\vtwice, exit 1invalid modifier '\#013' at position 1 in filter rule: +\#013foo, exit 1--filter=$'foo\vbar'Unknown filter rule: foo\#013bar, exit 1\v, exit 1Unknown filter rule: foo\#013bar, exit 1no\001pelink_stat ".../no\#001pe" failed, exit 23\001on both lines, exit 23link_stat ".../no\#001pe" failedon both lines, exit 23\#001, exit 23\#001, exit 23\#001, exit 23 (unchanged)no\tpecafé\001,LC_ALL=Ccaf\#303\#251\#001caf\#303\#251\#001café\001,-8orC.UTF-8caf+ rawé+\#001caf+ rawé+\#001Tests
crates/cli/tests/client_stderr_control_byte_escaping.rs:-8, and a control byte in an unknown rule. Each compares the cause line byte for byte, plus the exit code.MessageSinkunit tests, one per byte class:\#dddguard.write_escaped_line.write_refusal(VT) andwrite_terminal_line.Mutation: with the escaping switched off at each new site (the client sink flag, the
write_refusalstyle,MessageSink::escape_style,write_terminal_line), all 12 new tests fail: 4/4 cli, 6/6 logging-sink, 1/1 core, 1/1 logging.Multi-line causes
Escaping showed that oc folded some multi-line diagnostics into one line. Each such cause is now written one line per upstream
rprintfcall:Unexpected local arg: %sandIf arg is a remote file/dir, prefix it with a colon (:).are tworprintf(FERROR, ...)calls in 3.5.2 (main.c:1591-1592). oc built one cause with an embedded newline, so escaping printed\#012between the two parts. AClientErrorcause now holds one line per upstream call (cause_lines()), and the report writes each line through the escaper. A newline inside the operand itself is still escaped as\#012, as log.c:288-291 does.clap's parse error spans several lines. oc writes it line by line, so its own line breaks stay raw and only bytes inside each line are escaped. Upstream prints its option error as one popt line through
option_error()(options.c:2087-2090, options.c:933), then the trailer (main.c:1916-1917). The wording differs, and this PR does not change it:rsync: --version=extra: option does not take an argument, thenrsync error: syntax or usage error (code 1) at main.c(1917) [client=3.5.2]rsync error: syntax or usage error: unexpected value 'extra' for '--version...' found; no more were expected, a blank line,Usage: rsync --version... [args]..., then(code 1) [client=...]The unknown-option refusal and the failed
--log-fileopen line were raw writes. They now go through the escaper too. Measured: 3.5.2 printsrsync: --bo\#001gus: unknown option, and oc now prints the same line.A daemon that sends free text and then closes before acknowledging a module listing used to be reported as one message, with the received lines joined by newlines. Escaping would have printed
\#012between them. Upstream prints each received line with its ownrprintf(clientserver.c:428-429 for@ERROR, 438-439 for MOTD and listing lines). Each received line is now its own escaped stderr line, followed by the existingdaemon refused module listingtrailer. The trailer no longer repeats the lines. The connect-failure lines on that path also go through the escaper now.New tests in
crates/cli/src/frontend/tests/stderr_lines.rs. Each one fails with the split reverted:\#012module_listtest that the refusal keeps one cause line per received line)Gates (Linux host, on master 0c57d58)
cargo fmt --all -- --checkpython3 tools/ci/check_rustfmt_all.py--all-targets --all-features -D warnings)cargo check --workspace --all-features --all-targets --target x86_64-pc-windows-gnucargo clippy --workspace --all-features --all-targets --target x86_64-pc-windows-gnu --no-deps -- -D warningscargo run --locked -p xtask -- no-placeholderstools/ci/citation_drift_audit.py --ratchetOC_RSYNC_UPSTREAM_COMPAT=1)--lib(all frontend unit tests)stderr_lines+clapunderLC_ALL=CandLC_ALL=en_US.UTF-8module(module listing)module_list/list/client_output_locale_escaping,upstream_compat_filter_rule_parsessh_transportdaemon_pull_every_operandfilter_args,client::errorclient::remote::invocationmessage_sinkescape/argv_filters/,/daemon_filter/Remaining differences
link_stat ...line, then anrsync error: link_stat ... (code 23)trailer. 3.5.2 printsrsync: [sender] link_stat ..., thensome files/attrs were not transferred ... (code 23). That is a separate text-parity gap; this change only fixes the escaping.eprintln!diagnostics in the local-copy engine carry names that are not escaped yet. Examples:symlink has no referent,opendir,directory has vanished, and the skip notices. They can move toeprint_terminal_line()one by one.--server, and to the copy of a daemon's refusal on its own stderr.Closes #8884