]> granicus.if.org Git - python/commitdiff
#6707 fix a crash with dir() on an uninitialized module
authorBenjamin Peterson <benjamin@python.org>
Sat, 15 Aug 2009 13:16:38 +0000 (13:16 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 15 Aug 2009 13:16:38 +0000 (13:16 +0000)
Lib/test/test_module.py
Misc/NEWS
Objects/object.c

index 5bc33d46dd814d435f06c1dac3d3bfc959ca1f7e..80d440d215f61f65c0507f7f6ed9f770bc1b339a 100644 (file)
@@ -11,6 +11,7 @@ class ModuleTests(unittest.TestCase):
         # and __doc__ is None
         foo = ModuleType.__new__(ModuleType)
         self.assertTrue(foo.__dict__ is None)
+        self.assertRaises(SystemError, dir, foo)
         try:
             s = foo.__name__
             self.fail("__name__ = %s" % repr(s))
index 44db52cb7e1f94dfad637988b599edf49f79a7de..5c467aa658ed6c1edb6db4f3f3ce350e83d3819b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 1
 Core and Builtins
 -----------------
 
+- Issue #6707: dir() on an uninitialized module caused a crash.
+
 - Issue #6540: Fixed crash for bytearray.translate() with invalid parameters.
 
 - Issue #6573: set.union() stopped processing inputs if an instance of self
index 0191ebe61d840f5aa6c516360d8573cd8aa29287..3c7facb4c3255109258846dafdc7317cc515cda7 100644 (file)
@@ -1810,9 +1810,11 @@ _specialized_dir_module(PyObject *obj)
                if (PyDict_Check(dict))
                        result = PyDict_Keys(dict);
                else {
-                       PyErr_Format(PyExc_TypeError,
-                                    "%.200s.__dict__ is not a dictionary",
-                                    PyModule_GetName(obj));
+                       char *name = PyModule_GetName(obj);
+                       if (name)
+                               PyErr_Format(PyExc_TypeError,
+                                            "%.200s.__dict__ is not a dictionary",
+                                            name);
                }
        }