Skip to content

Commit b729b2d

Browse files
committed
Validate rsync_rsh options to prevent NUL bytes and improve argument handling
1 parent 5205dbd commit b729b2d

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

contrib/rsync.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115

116116
use Deployer\Host\Localhost;
117117
use Deployer\Task\Context;
118+
118119
use function Deployer\Support\rsync_rsh;
119120

120121
set('rsync', [

src/Command/SshCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Console\Input\InputInterface;
2222
use Symfony\Component\Console\Output\OutputInterface;
2323
use Symfony\Component\Console\Question\ChoiceQuestion;
24+
2425
use function Deployer\quote;
2526

2627
/**

src/Support/helpers.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,16 @@ function deployer_root(): string
254254
*/
255255
function rsync_rsh(array $args): string
256256
{
257-
$rsh = 'ssh ';
257+
$parts = ['ssh'];
258258
foreach ($args as $option) {
259+
if (str_contains($option, "\0")) {
260+
throw new \InvalidArgumentException('rsync_rsh: NUL byte not allowed in ssh option');
261+
}
259262
if (preg_match('/^[a-zA-Z0-9_\-=]+$/', $option)) {
260-
$rsh .= ' ' . $option;
263+
$parts[] = $option;
261264
} else {
262-
$rsh .= '"' . addslashes($option) . '" ';
265+
$parts[] = "'" . str_replace("'", "''", $option) . "'";
263266
}
264267
}
265-
return $rsh;
268+
return implode(' ', $parts);
266269
}

0 commit comments

Comments
 (0)