Skip to content

Commit 2af7685

Browse files
committed
Merge pull request #699 from layus/master
Harden system calls to git Fixes from PR #684 (cameris/master) re-applied to new function 's:make_git_command' Conflicts: autoload/vundle/installer.vim autoload/vundle/scripts.vim
2 parents 1d1c2b0 + 4629700 commit 2af7685

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

autoload/vundle/installer.vim

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ endf
343343
" return -- the URL for the origin remote (string)
344344
" ---------------------------------------------------------------------------
345345
func! s:get_current_origin_url(bundle) abort
346-
let cmd = 'cd '.vundle#installer#shellesc(a:bundle.path()).' && '.
347-
g:vundle#git_executable.' config --get remote.origin.url'
348-
let cmd = vundle#installer#shellesc_cd(cmd)
346+
let cmd = s:make_git_command(a:bundle, ['config', '--get', 'remote.origin.url'])
349347
let out = s:strip(s:system(cmd))
350348
return out
351349
endf
@@ -358,13 +356,37 @@ endf
358356
" return -- A 15 character log sha for the current HEAD
359357
" ---------------------------------------------------------------------------
360358
func! s:get_current_sha(bundle)
361-
let cmd = 'cd '.vundle#installer#shellesc(a:bundle.path()).' && '.
362-
g:vundle#git_executable.' rev-parse HEAD'
363-
let cmd = vundle#installer#shellesc_cd(cmd)
359+
let cmd = s:make_git_command(a:bundle, ['rev-parse', 'HEAD'])
364360
let out = s:system(cmd)[0:15]
365361
return out
366362
endf
367363

364+
" ---------------------------------------------------------------------------
365+
" Build a safe (escaped) git command
366+
"
367+
" bundle -- A bundle object to get the path to the git dir
368+
" args -- A list of arguments to the git executable
369+
" return -- A string containing the escaped shell command
370+
" ---------------------------------------------------------------------------
371+
func! s:make_git_command(bundle, args) abort
372+
let workdir = a:bundle.path()
373+
let gitdir = workdir.'/.git/'
374+
375+
let git = [g:vundle#git_executable, '--git-dir='.gitdir, '--work-tree='.workdir]
376+
377+
return join(map(git + a:args, 'vundle#installer#shellesc(v:val)'))
378+
endf
379+
380+
" ---------------------------------------------------------------------------
381+
" Build a safe (escaped) command from list of git args
382+
"
383+
" bundle -- A bundle object to get the path to the git dir
384+
" argss -- A list of lists of arguments to successive git calls
385+
" return -- A string containing the escaped shell command
386+
" ---------------------------------------------------------------------------
387+
func! s:make_git_commands(bundle, argss) abort
388+
return join(map(a:argss, 's:make_git_command(a:bundle, v:val)'), ' && ')
389+
endf
368390

369391
" ---------------------------------------------------------------------------
370392
" Create the appropriate sync command to run according to the current state of
@@ -390,14 +412,12 @@ func! s:make_sync_command(bang, bundle) abort
390412
call s:log('> Plugin ' . a:bundle.name . ' new URI: ' . a:bundle.uri)
391413
" Directory names match but the origin remotes are not the same
392414
let cmd_parts = [
393-
\ 'cd '.vundle#installer#shellesc(a:bundle.path()) ,
394-
\ g:vundle#git_executable.' remote set-url origin ' . vundle#installer#shellesc(a:bundle.uri),
395-
\ g:vundle#git_executable.' fetch',
396-
\ g:vundle#git_executable.' reset --hard origin/HEAD',
397-
\ g:vundle#git_executable.' submodule update --init --recursive',
398-
\ ]
399-
let cmd = join(cmd_parts, ' && ')
400-
let cmd = vundle#installer#shellesc_cd(cmd)
415+
\ [ 'remote', 'set-url', 'origin', a:bundle.uri ],
416+
\ [ 'fetch' ],
417+
\ [ 'reset', '--hard', 'origin/HEAD' ],
418+
\ [ 'submodule', 'update', '--init', '--recursive' ]
419+
\]
420+
let cmd = s:make_git_commands(a:bundle, cmd_parts)
401421
let initial_sha = ''
402422
return [cmd, initial_sha]
403423
endif

autoload/vundle/scripts.vim

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,8 @@ func! s:create_changelog() abort
8484
let updated_sha = bundle_data[1]
8585
let bundle = bundle_data[2]
8686

87-
let cmd = 'cd '.vundle#installer#shellesc(bundle.path()).
88-
\ ' && '.g:vundle#git_executable.' log --pretty=format:"%s %an, %ar" --graph '.
89-
\ initial_sha.'..'.updated_sha
90-
91-
let cmd = vundle#installer#shellesc_cd(cmd)
87+
let cmd = s:make_git_command(bundle, ['log', '--pretty=format:"%s %an, %ar"',
88+
\ '--graph', initial_sha.'..'.updated_sha ])
9289

9390
let updates = system(cmd)
9491

0 commit comments

Comments
 (0)