]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1440: "rvim" can execute a shell through :diffpatch v9.0.1440
authorBram Moolenaar <Bram@vim.org>
Tue, 4 Apr 2023 21:04:53 +0000 (22:04 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 4 Apr 2023 21:04:53 +0000 (22:04 +0100)
Problem:    "rvim" can execute a shell through :diffpatch.
Solution:   Disallow the shell "patch" command.

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

index a46f0bf81e7fb632b6bec590d3955287b29c14d0..1873767106b412ae6f708e3cca4504c5b3eb6677 100644 (file)
@@ -1310,6 +1310,9 @@ ex_diffpatch(exarg_T *eap)
     else
 #endif
     {
+       if (check_restricted())
+           goto theend;
+
        // 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",
@@ -1380,7 +1383,8 @@ ex_diffpatch(exarg_T *eap)
 
                    // Do filetype detection with the new name.
                    if (au_has_group((char_u *)"filetypedetect"))
-                       do_cmdline_cmd((char_u *)":doau filetypedetect BufRead");
+                       do_cmdline_cmd(
+                                    (char_u *)":doau filetypedetect BufRead");
                }
            }
        }
index d60de5046c0aae9ece9a74dc71966f494a06ebd0..cb042e115ad7797ef059d6ed6c6ffb58ffcd9750 100644 (file)
@@ -736,6 +736,21 @@ func Test_diffpatch()
   bwipe!
 endfunc
 
+" FIXME: test fails, the Xresult file can't be read
+func No_Test_diffpatch_restricted()
+  let lines =<< trim END
+    call assert_fails('diffpatch NoSuchDiff', 'E145:')
+
+    call writefile(v:errors, 'Xresult')
+    qa!
+  END
+  call writefile(lines, 'Xrestricted', 'D')
+  if RunVim([], [], '-Z --clean -S Xrestricted')
+    call assert_equal([], readfile('Xresult'))
+  endif
+  call delete('Xresult')
+endfunc
+
 func Test_diff_too_many_buffers()
   for i in range(1, 8)
     exe "new Xtest" . i
index 5cace2e388578419842d7de3b860f4a44b995523..853ea5f181dfb98eed21e19fdfc65853956c8643 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1440,
 /**/
     1439,
 /**/