summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-10-01 15:24:50 (GMT)
committerGuido van Rossum <guido@python.org>1998-10-01 15:24:50 (GMT)
commit566373e974413de66ad1d627f322908597eb2efd (patch)
treeebab60f96f9115d224389f27a66c82cac1cfd742
parent231c8c0895996e8c8936eef5bd2df84999e9409a (diff)
downloadcpython-566373e974413de66ad1d627f322908597eb2efd.zip
cpython-566373e974413de66ad1d627f322908597eb2efd.tar.gz
cpython-566373e974413de66ad1d627f322908597eb2efd.tar.bz2
While scalling sys.modules, skip entries that don't have string keys,
to protect us from jokers who put items with non-string keys in sys.modules. Reported by Greg Stein.
-rw-r--r--Python/import.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/Python/import.c b/Python/import.c
index 5c8d939..c8bbc29 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -274,8 +274,8 @@ PyImport_Cleanup()
while (PyDict_Next(modules, &pos, &key, &value)) {
if (value->ob_refcnt != 1)
continue;
- if (PyModule_Check(value)) {
- name = PyString_AsString(key);
+ if (PyString_Check(key) && PyModule_Check(value)) {
+ name = PyString_AS_STRING(key);
if (strcmp(name, "__builtin__") == 0)
continue;
if (strcmp(name, "sys") == 0)
@@ -293,8 +293,8 @@ PyImport_Cleanup()
/* Next, delete all modules (still skipping __builtin__ and sys) */
pos = 0;
while (PyDict_Next(modules, &pos, &key, &value)) {
- if (PyModule_Check(value)) {
- name = PyString_AsString(key);
+ if (PyString_Check(key) && PyModule_Check(value)) {
+ name = PyString_AS_STRING(key);
if (strcmp(name, "__builtin__") == 0)
continue;
if (strcmp(name, "sys") == 0)