Skip to content

Quote rsync transport safely - #68

Open
salva wants to merge 1 commit into
masterfrom
fix/rsync-transport-quoting
Open

Quote rsync transport safely#68
salva wants to merge 1 commit into
masterfrom
fix/rsync-transport-quoting

Conversation

@salva

@salva salva commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

Make rsync transport command quoting safe for POSIX shell command strings.

Changes

  • Quote every transport argument with POSIX single-quote escaping.
  • Preserve embedded single quotes.
  • Double all % characters, not just the first one.
  • Add focused regression tests for whitespace, single quotes, percent escaping, and list context.
  • Add the new test to MANIFEST.

Fixes #41.

Testing

  • perl -Ilib -c lib/Net/OpenSSH.pm
  • perl -Ilib t/rsync-quote.t

Copilot AI review requested due to automatic review settings June 4, 2026 12:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make the rsync -e transport command construction shell-safe by consistently quoting transport arguments and adding regression tests to prevent future quoting/escaping regressions.

Changes:

  • Update _rsync_quote to quote all rsync transport arguments and to escape % globally.
  • Add a focused regression test covering whitespace, single quotes, percent escaping, and list context behavior.
  • Register the new test in MANIFEST.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/Net/OpenSSH.pm Updates rsync transport argument quoting/escaping logic used to build the -e command string.
t/rsync-quote.t Adds regression tests for _rsync_quote behavior.
MANIFEST Includes the new test file in the distribution manifest.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Net/OpenSSH.pm
Comment on lines +643 to +645
s/%/%%/g;
s/'/'\\''/g;
$_ = qq|'$_'|;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a false positive. The substitution produces the standard POSIX shell form 'a'\''b', not a backslash inside a single-quoted string. I verified both the unit test and an actual shell round-trip on this branch:\n\nperl -Ilib t/rsync-quote.t passes.\n\nperl -Ilib -MNet::OpenSSH -e 'print Net::OpenSSH->_rsync_quote(q(a'"'"'b)), qq(\n)' prints 'a'\''b'.\n\nPassing that quoted string through sh -c 'printf %s ...' produces a'b.

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.

rsync transport quoting is not shell-safe

2 participants