Commits

Yuya Nishihara committed a815907

hgext: wrap extensions.loadpath() to detect loading unwanted extension

Comments (0)

Files changed (1)

hgext/chgsupport.py

             raise TaintedWorkerError('loaded local command or alias')
         if origextcnt != len(extensions._extensions):
             raise TaintedWorkerError('loaded local extension')
+        if _extensionsloadedbypath:
+            raise TaintedWorkerError('loaded unwanted extension')
 
 def _disablepager():
     try:
         return
     extensions.wrapfunction(pagermod, '_runpager', lambda orig, p: None)
 
+# extensions.disabledcmd() uses .loadpath(), but .loadpath() does not
+# remember loaded extension in _extensions list. Since bad-mannered extension
+# may mangle global object, we need to restart cmdserver process even if
+# uisetup() or extsetup() is not called.
+_extensionsloadedbypath = False
+def _extensionsloadpath(orig, path, module_name):
+    global _extensionsloadedbypath
+    ext = orig(path, module_name)
+    _extensionsloadedbypath = True
+    return ext
+
 def _serve(orig, ui, repo, **opts):
     mode = opts['cmdserver']
     if not mode or mode != 'unix':
         return orig(ui, repo, **opts)
 
     _disablepager()
+    extensions.wrapfunction(extensions, 'loadpath', _extensionsloadpath)
 
     # it might be confusing to reuse --port option
     sockpath = opts['port']