File tree Expand file tree Collapse file tree 3 files changed +14
-9
lines changed
Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ appear at the top.
66## [ Unreleased] [ ]
77
88 * Your contribution here!
9+ * [ #453 ] ( https://github.com/capistrano/sshkit/pull/453 ) : fix and unify shell escaping for user/group/directory - [ @grosser ] ( https://github.com/grosser )
910
1011## [ 1.18.2] [ ] (2019-02-03)
1112
Original file line number Diff line number Diff line change 1+ require 'shellwords'
2+
13module SSHKit
24
35 module Backend
@@ -81,12 +83,12 @@ def execute(*args)
8183 def within ( directory , &_block )
8284 ( @pwd ||= [ ] ) . push directory . to_s
8385 execute <<-EOTEST , verbosity : Logger ::DEBUG
84- if test ! -d #{ File . join ( @pwd ) }
85- then echo "Directory does not exist '#{ File . join ( @pwd ) } '" 1>&2
86+ if test ! -d #{ File . join ( @pwd ) . shellescape }
87+ then echo "Directory does not exist '#{ File . join ( @pwd ) . shellescape } '" 1>&2
8688 false
8789 fi
88- EOTEST
89- yield
90+ EOTEST
91+ yield
9092 ensure
9193 @pwd . pop
9294 end
@@ -108,8 +110,8 @@ def as(who, &_block)
108110 @group = nil
109111 end
110112 execute <<-EOTEST , verbosity : Logger ::DEBUG
111- if ! sudo -u #{ @user } whoami > /dev/null
112- then echo "You cannot switch to user '#{ @user } ' using sudo, please check the sudoers file" 1>&2
113+ if ! sudo -u #{ @user . to_s . shellescape } whoami > /dev/null
114+ then echo "You cannot switch to user '#{ @user . to_s . shellescape } ' using sudo, please check the sudoers file" 1>&2
113115 false
114116 fi
115117 EOTEST
Original file line number Diff line number Diff line change @@ -162,13 +162,15 @@ def environment_string
162162 end
163163
164164 def with ( &_block )
165- return yield unless environment_hash . any?
166- "( export #{ environment_string } ; #{ yield } )"
165+ env_string = environment_string
166+ return yield if env_string . empty?
167+ "( export #{ env_string } ; #{ yield } )"
167168 end
168169
169170 def user ( &_block )
170171 return yield unless options [ :user ]
171- "sudo -u #{ options [ :user ] . to_s . shellescape } #{ environment_string + " " unless environment_string . empty? } -- sh -c #{ yield . shellescape } "
172+ env_string = environment_string
173+ "sudo -u #{ options [ :user ] . to_s . shellescape } #{ env_string + " " unless env_string . empty? } -- sh -c #{ yield . shellescape } "
172174 end
173175
174176 def in_background ( &_block )
You can’t perform that action at this time.
0 commit comments