aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload/python3complete.vim
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2026-05-30 11:41:48 +0800
committerzeertzjq <zeertzjq@outlook.com>2026-05-30 11:46:27 +0800
commitde8c2db57796a18d918def998526d68ae50c9ed0 (patch)
treed17506c7f3ae09707a922e10278a242625274a8e /runtime/autoload/python3complete.vim
parent8b5a8c12cd7d176908c5db7890c8d8059d446a71 (diff)
downloadrneovim-de8c2db57796a18d918def998526d68ae50c9ed0.tar.gz
rneovim-de8c2db57796a18d918def998526d68ae50c9ed0.tar.bz2
rneovim-de8c2db57796a18d918def998526d68ae50c9ed0.zip
vim-patch:9.2.0561: [security]: possible code execution with python3complete
Problem: [security]: possible code execution with python3complete Solution: Disable execution of import/from statements Github Security Advisory: https://github.com/vim/vim/security/advisories/GHSA-52mc-rq6p-rc7c https://github.com/vim/vim/commit/4b850457e12e1a678dd209f2868154f7553cbf8d Co-authored-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'runtime/autoload/python3complete.vim')
-rw-r--r--runtime/autoload/python3complete.vim17
1 files changed, 14 insertions, 3 deletions
diff --git a/runtime/autoload/python3complete.vim b/runtime/autoload/python3complete.vim
index ca5707d31f..1f074305f1 100644
--- a/runtime/autoload/python3complete.vim
+++ b/runtime/autoload/python3complete.vim
@@ -14,6 +14,10 @@
" i.e. "import url<c-x,c-o>"
" Continue parsing on invalid line??
"
+" v 0.10 by Vim project
+" * disables importing local modules, unless the global Vim variable
+" g:pythoncomplete_allow_import is set to non-zero
+"
" v 0.9
" * Fixed docstring parsing for classes and functions
" * Fixed parsing of *args and **kwargs type arguments
@@ -132,11 +136,20 @@ class Completer(object):
def evalsource(self,text,line=0):
sc = self.parser.parse(text,line)
+ try: allow_imports = int(
+ vim.eval("get(g:, 'pythoncomplete_allow_import', 0)"))
+ except Exception:
+ allow_imports = 0
src = sc.get_code()
dbg("source: %s" % src)
try: exec(src,self.compldict)
except: dbg("parser: %s, %s" % (sys.exc_info()[0],sys.exc_info()[1]))
for l in sc.locals:
+ # Executing import/from statements harvested from the buffer runs
+ # arbitrary package code; only do so when the user opted in.
+ if not allow_imports and (l.startswith('import')
+ or l.startswith('from ')):
+ continue
try: exec(l,self.compldict)
except: dbg("locals: %s, %s [%s]" % (sys.exc_info()[0],sys.exc_info()[1],l))
@@ -300,13 +313,11 @@ class Scope(object):
def get_code(self):
str = ""
if len(self.docstr) > 0: str += '"""'+self.docstr+'"""\n'
- for l in self.locals:
- if l.startswith('import'): str += l+'\n'
str += 'class _PyCmplNoType:\n def __getattr__(self,name):\n return None\n'
for sub in self.subscopes:
str += sub.get_code()
for l in self.locals:
- if not l.startswith('import'): str += l+'\n'
+ if not l.startswith('import') and not l.startswith('from '): str += l+'\n'
return str