[issue18426] Crash when extension does not use PyModule_Create()

Christian Heimes report at bugs.python.org
Thu Jul 11 11:57:06 CEST 2013


Christian Heimes added the comment:

In theory you are right. m->md_def could be NULL, too. But in practice it's only going to happen when you have a faulty C extension. The code tries to load a dynamic module (ELF shared library, Windows DLL, ...) with _PyImport_GetDynLoadFunc() a couple of lines before PyModule_GetDef(). Any invalid file is rejected:

>>> imp.load_dynamic("os", "Lib/os.py")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: Lib/os.py: invalid ELF header

But an extra check doesn't hurt. How do you like this?

    def = PyModule_GetDef(m);
    if (def == NULL) {
        if (!PyErr_Occured()) {
            /* m->md_def == NULL */
            PyErr_BadArgument();
        }
        goto error;
    }

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18426>
_______________________________________


More information about the Python-bugs-list mailing list