Skip to content

Commit d27c983

Browse files
committed
Ensure that the git pre-processor doesn't accidentally bail also
1 parent 99fec61 commit d27c983

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/cocoapods-downloader/git.rb

+6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ def checkout_options
2323
def self.preprocess_options(options)
2424
return options unless options[:branch]
2525

26+
input = [options[:git], options[:commit]].map(&:to_s)
27+
invalid = input.compact.any? { |value| value.start_with?('--') || value.include?(' --') }
28+
raise DownloaderError, "Provided unsafe input for git #{options}." if invalid
29+
2630
command = ['ls-remote',
31+
'--',
2732
options[:git],
2833
options[:branch]]
34+
2935
output = Git.execute_command('git', command)
3036
match = commit_from_ls_remote output, options[:branch]
3137

spec/git_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ def ensure_only_one_ref(folder)
289289
new_options = Downloader.preprocess_options(options)
290290
new_options[:branch].should == 'aaaa'
291291
end
292+
293+
it 'throws when proving an invalid input' do
294+
options = { :git => '--upload-pack=touch ./HELLO1;', :branch => 'foo' }
295+
e = lambda { Downloader.preprocess_options(options) }.should.raise DownloaderError
296+
e.message.should.match /Provided unsafe input/
297+
end
292298
end
293299

294300
describe ':bad input' do

0 commit comments

Comments
 (0)