]> granicus.if.org Git - python/commitdiff
While scalling sys.modules, skip entries that don't have string keys,
authorGuido van Rossum <guido@python.org>
Thu, 1 Oct 1998 15:24:50 +0000 (15:24 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 1 Oct 1998 15:24:50 +0000 (15:24 +0000)
to protect us from jokers who put items with non-string keys in
sys.modules.  Reported by Greg Stein.

Python/import.c

index 5c8d9399794d59c241eba7e76f69452fa3333046..c8bbc29a45efba971d2d62eed5fa22fe42425023 100644 (file)
@@ -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)