[Python-checkins] r55704 - python/branches/bcannon-objcap/secure_python.c

brett.cannon python-checkins at python.org
Thu May 31 02:36:56 CEST 2007


Author: brett.cannon
Date: Thu May 31 02:36:51 2007
New Revision: 55704

Modified:
   python/branches/bcannon-objcap/secure_python.c
Log:
Clear sys.meta_path and sys.path_hooks.


Modified: python/branches/bcannon-objcap/secure_python.c
==============================================================================
--- python/branches/bcannon-objcap/secure_python.c	(original)
+++ python/branches/bcannon-objcap/secure_python.c	Thu May 31 02:36:51 2007
@@ -22,6 +22,7 @@
     int return_val;
     PyInterpreterState *interp;
     Py_ssize_t module_count, x;
+    PyObject *obj;
     PyObject *module_names_list;
     PyObject *hidden_modules;
     PyObject *import_module;
@@ -52,12 +53,24 @@
     /* Initialize interpreter.  */
     Py_Initialize();
 
+    interp = PyThreadState_GET()->interp;
+
+    /* Clear sys.meta_path and sys.path_hooks.
+       This needs to be done before importlib is called as it sets values in
+       both attributes. */
+    obj = PyDict_GetItemString(interp->sysdict, "meta_path");
+    x = PyList_Size(obj);
+    PyList_SetSlice(obj, 0, x, NULL);
+
+    obj = PyDict_GetItemString(interp->sysdict, "path_hooks");
+    x = PyList_Size(obj);
+    PyList_SetSlice(obj, 0, x, NULL);
+
     /* Create lists of modules safe to import. */
     CREATE_SAFE_LIST(builtins);
     CREATE_SAFE_LIST(frozen);
     CREATE_SAFE_LIST(extensions);
 
-    interp = PyThreadState_GET()->interp;
 
     /* Get importer from importlib. */
     import_module = PyImport_ImportModule("controlled_importlib");


More information about the Python-checkins mailing list