]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0198: cscope: can escape from restricted mode v9.2.0198
authorChristian Brabandt <cb@256bit.org>
Wed, 18 Mar 2026 21:27:38 +0000 (21:27 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 18 Mar 2026 21:29:13 +0000 (21:29 +0000)
Problem:  cscope: can escape from restricted mode (pyllyukko)
Solution: Disallow :cscope in restricted mode (like :grep),
          add a tests for restricted mode using :grep and :cscope

closes: #19731

Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/version9.txt
src/if_cscope.c
src/testdir/test_restricted.vim
src/version.c

index 2106a1e40763932ccf1aa0f8bd238a2376c6c3ca..79536bc988020e437d79fdb711c16e63e6cfd38e 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt* For Vim version 9.2.  Last change: 2026 Mar 17
+*version9.txt* For Vim version 9.2.  Last change: 2026 Mar 18
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -52600,6 +52600,8 @@ Restricted mode~
 Using external diff mode or setting environment variables is no longer allowed
 when Vim is running in |restricted-mode|.
 
+Using |:cscope| is no longer allowed.
+
 Other ~
 -----
 - The new |xdg.vim| script for full XDG compatibility is included.
index 5c8f9ff4770f4499857157a9a2d7b1611ad95d39..10437a532b6b9acd246b629d71babd3d80fe2f8b 100644 (file)
@@ -254,6 +254,9 @@ do_cscope_general(
 {
     cscmd_T *cmdp;
 
+    if (check_restricted())
+       return;
+
     if ((cmdp = cs_lookup_cmd(eap)) == NULL)
     {
        cs_help(eap);
index 2d8f483c228f9ce23083a2953141967583659d7a..2d8c8ce5f73db5e798678de6a7e945b053f914a3 100644 (file)
@@ -176,4 +176,48 @@ func Test_restricted_env()
   call delete('XResult_env')
 endfunc
 
+func Test_restricted_grep()
+  CheckScreendump
+
+  let lines =<< trim END
+    let result = 'okay'
+    try
+      " Try to use grep to execute an external command
+      grep 'Vim' ./*.vim
+    catch /^Vim\%((\S\+)\)\=:E145:/
+      let result = 'grep-blocked'
+    endtry
+    call writefile([result], 'XResult_grep')
+    qa!
+  END
+
+  call writefile(lines, 'Xrestricted_grep', 'D')
+  if RunVim([], [], '-Z --clean -S Xrestricted_grep')
+    call assert_equal(['grep-blocked'], readfile('XResult_grep'))
+  endif
+  call delete('XResult_grep')
+endfunc
+
+func Test_restricted_cscope()
+  CheckFeature cscope
+
+  " File does not exist, but shouldn't matter, it must be disallowed
+  let lines =<< trim END
+    let result = 'okay'
+    try
+      cscope add Xfoobar.out
+    catch /^Vim\%((\S\+)\)\=:E145:/
+      let result = 'blocked'
+    endtry
+    call writefile([result], 'XResult_cscope')
+    qa!
+  END
+
+  call writefile(lines, 'Xrestricted_cscope', 'D')
+  if RunVim([], [], '-Z --clean -S Xrestricted_cscope')
+    call assert_equal(['blocked'], readfile('XResult_cscope'))
+  endif
+  call delete('XResult_cscope')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 9d5bbf02dabffc37c5aec64be5147da54adfa6bf..b47f10e3639f0f6b6f07c97a2c90f10e6d47f21b 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    198,
 /**/
     197,
 /**/