]> granicus.if.org Git - vim/commitdiff
patch 8.0.0442: patch shell command not well escaped v8.0.0442
authorBram Moolenaar <Bram@vim.org>
Thu, 9 Mar 2017 18:21:30 +0000 (19:21 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 9 Mar 2017 18:21:30 +0000 (19:21 +0100)
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)

src/diff.c
src/testdir/test_diffmode.vim
src/version.c

index b64b45ce9607feabe48a9cbd5da3d6cd17fe2ee0..7b81feba7aa59359ea00137b12c3a83aa27e6d30 100644 (file)
@@ -977,7 +977,12 @@ ex_diffpatch(exarg_T *eap)
     {
        /* Build the patch command and execute it.  Ignore errors.  Switch to
         * cooked mode to allow the user to respond to prompts. */
-       vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"",
+       vim_snprintf((char *)buf, buflen,
+#ifdef UNIX
+               "patch -o %s %s < '%s'",
+#else
+               "patch -o %s %s < \"%s\"",
+#endif
                tmp_new, tmp_orig,
 # ifdef UNIX
                fullname != NULL ? fullname :
index 73f944bcead1b10880065ad1188beafeeed4086c..c23e8a1da5b56d59746fcc5d73e4f49b7ebf5699 100644 (file)
@@ -318,9 +318,20 @@ func Test_diffpatch()
   bwipe!
   new
   call assert_fails('diffpatch Xpatch', 'E816:')
-  call setline(1, ['1', '2', '3'])
-  diffpatch Xpatch
-  call assert_equal(['1', '2x', '3', '4'], getline(1, '$'))
+
+  for name in ['Xpatch', 'Xpatch$HOME']
+    call setline(1, ['1', '2', '3'])
+    if name != 'Xpatch'
+      call rename('Xpatch', name)
+    endif
+    exe 'diffpatch ' . escape(name, '$')
+    call assert_equal(['1', '2x', '3', '4'], getline(1, '$'))
+    if name != 'Xpatch'
+      call rename(name, 'Xpatch')
+    endif
+    bwipe!
+  endfor
+
   call delete('Xpatch')
   bwipe!
 endfunc
index aee70ef655277544703c15cc2a3e8cd5d5087e19..0f7b4e499f70015f9e263b48ec30b5343b6213b1 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    442,
 /**/
     441,
 /**/