From f492c364427eb0224fa242ae938cc3cc98f7fe51 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 15 Aug 2009 13:18:47 +0000 Subject: Merged revisions 74457 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74457 | benjamin.peterson | 2009-08-15 08:16:38 -0500 (Sat, 15 Aug 2009) | 1 line #6707 fix a crash with dir() on an uninitialized module ........ --- Lib/test/test_module.py | 1 + Misc/NEWS | 2 ++ Objects/object.c | 8 +++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py index e0c7ec3..ac99773 100644 --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -11,6 +11,7 @@ class ModuleTests(unittest.TestCase): # and __doc__ is None foo = ModuleType.__new__(ModuleType) self.failUnless(foo.__dict__ is None) + self.assertRaises(SystemError, dir, foo) try: s = foo.__name__ self.fail("__name__ = %s" % repr(s)) diff --git a/Misc/NEWS b/Misc/NEWS index 8b0f7ab..4b8bb70 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.6.3 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 diff --git a/Objects/object.c b/Objects/object.c index bb3693b..0e97e8c 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1806,9 +1806,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); } } -- cgit v0.12