Skip to content

Commit 1ef73e3

Browse files
committed
patch 8.0.0442: patch shell command not well escaped
Problem: Patch shell command uses double quotes around the argument, which allows for $HOME to be expanded. (Etienne) Solution: Use single quotes on Unix. (closes #1543)
1 parent ad2cfb5 commit 1ef73e3

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/diff.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,12 @@ ex_diffpatch(exarg_T *eap)
977977
{
978978
/* Build the patch command and execute it. Ignore errors. Switch to
979979
* cooked mode to allow the user to respond to prompts. */
980-
vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"",
980+
vim_snprintf((char *)buf, buflen,
981+
#ifdef UNIX
982+
"patch -o %s %s < '%s'",
983+
#else
984+
"patch -o %s %s < \"%s\"",
985+
#endif
981986
tmp_new, tmp_orig,
982987
# ifdef UNIX
983988
fullname != NULL ? fullname :

src/testdir/test_diffmode.vim

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,20 @@ func Test_diffpatch()
318318
bwipe!
319319
new
320320
call assert_fails('diffpatch Xpatch', 'E816:')
321-
call setline(1, ['1', '2', '3'])
322-
diffpatch Xpatch
323-
call assert_equal(['1', '2x', '3', '4'], getline(1, '$'))
321+
322+
for name in ['Xpatch', 'Xpatch$HOME']
323+
call setline(1, ['1', '2', '3'])
324+
if name != 'Xpatch'
325+
call rename('Xpatch', name)
326+
endif
327+
exe 'diffpatch ' . escape(name, '$')
328+
call assert_equal(['1', '2x', '3', '4'], getline(1, '$'))
329+
if name != 'Xpatch'
330+
call rename(name, 'Xpatch')
331+
endif
332+
bwipe!
333+
endfor
334+
324335
call delete('Xpatch')
325336
bwipe!
326337
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
442,
767769
/**/
768770
441,
769771
/**/

0 commit comments

Comments
 (0)