Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 9187:e21d0798c02a legacy-trunk
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.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 01 Oct 1998 15:24:50 +0000 |
| parents | 2088f80253db |
| children | 07dae6fdae79 |
line wrap: on
line diff
--- a/Python/import.c Thu Oct 01 14:26:57 1998 +0000 +++ b/Python/import.c Thu Oct 01 15:24:50 1998 +0000 @@ -274,8 +274,8 @@ 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 @@ /* 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)
