2013-08-12 09:21:11 +02:00
|
|
|
Index: vim74/src/if_python.c
|
|
|
|
===================================================================
|
|
|
|
--- vim74.orig/src/if_python.c
|
|
|
|
+++ vim74/src/if_python.c
|
|
|
|
@@ -806,6 +806,7 @@ py_memsave(void *p, size_t len)
|
|
|
|
*/
|
|
|
|
|
2009-02-26 12:46:59 +01:00
|
|
|
static int PythonMod_Init(void);
|
|
|
|
+static void Python_FixPath(void);
|
|
|
|
|
2013-08-12 09:21:11 +02:00
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
@@ -933,6 +934,11 @@ Python_Init(void)
|
2009-02-26 12:46:59 +01:00
|
|
|
* the current directory in sys.path. */
|
|
|
|
PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)");
|
|
|
|
|
2013-02-22 12:50:58 +01:00
|
|
|
+ /* Remove empty elements from sys.path since that causes the PWD to be
|
|
|
|
+ * used for imports, possibly masking system libraries and/or running
|
|
|
|
+ * arbitrary code. */
|
|
|
|
+ Python_FixPath();
|
2009-02-26 12:46:59 +01:00
|
|
|
+
|
2013-02-22 12:50:58 +01:00
|
|
|
/* lock is created and acquired in PyEval_InitThreads() and thread
|
|
|
|
* state is created in Py_Initialize()
|
|
|
|
* there _PyGILState_NoteThreadState() also sets gilcounter to 1
|
2013-08-12 09:21:11 +02:00
|
|
|
@@ -1417,6 +1423,28 @@ PythonMod_Init(void)
|
2009-02-26 12:46:59 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ static void
|
|
|
|
+Python_FixPath(void)
|
|
|
|
+{
|
|
|
|
+ PyObject *sys = PyImport_ImportModule("sys");
|
|
|
|
+ PyObject *sysdict = PyModule_GetDict(sys);
|
|
|
|
+ PyObject *path = PyDict_GetItemString(sysdict, "path");
|
|
|
|
+ PyObject *newpath = PyList_New(0);
|
|
|
|
+ if (newpath != NULL) {
|
|
|
|
+ Py_INCREF(newpath);
|
|
|
|
+ PyInt n = PyList_Size(path);
|
|
|
|
+ PyInt i;
|
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
|
+ PyObject *item = PyList_GetItem(path, i);
|
|
|
|
+ if (strlen(PyString_AsString(item)) != 0) {
|
|
|
|
+ PyList_Append(newpath, PyList_GetItem(path, i));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ PyDict_SetItemString(sysdict, "path", newpath);
|
|
|
|
+ Py_DECREF(newpath);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
/*************************************************************************
|
|
|
|
* 4. Utility functions for handling the interface between Vim and Python.
|
|
|
|
*/
|