There was an error while loading. Please reload this page.
1 parent 6db7033 commit 9974e1bCopy full SHA for 9974e1b
3 files changed
Lib/test/test_imp.py
@@ -313,6 +313,17 @@ def test_load_source(self):
313
with self.assertRaisesRegex(ValueError, 'embedded null'):
314
imp.load_source(__name__, __file__ + "\0")
315
316
+ @support.cpython_only
317
+ def test_issue31315(self):
318
+ # There shouldn't be an assertion failure in imp.create_dynamic(),
319
+ # when spec.name is not a string.
320
+ create_dynamic = support.get_attribute(imp, 'create_dynamic')
321
+ class BadSpec:
322
+ name = None
323
+ origin = 'foo'
324
+ with self.assertRaises(TypeError):
325
+ create_dynamic(BadSpec())
326
+
327
328
class ReloadTests(unittest.TestCase):
329
Misc/NEWS.d/next/Core and Builtins/2017-09-01-00-40-58.bpo-31315.ZX20bl.rst
@@ -0,0 +1,2 @@
1
+Fix an assertion failure in imp.create_dynamic(), when spec.name is not a
2
+string. Patch by Oren Milman.
Python/importdl.c
@@ -103,6 +103,11 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
103
if (name_unicode == NULL) {
104
return NULL;
105
}
106
+ if (!PyUnicode_Check(name_unicode)) {
107
+ PyErr_SetString(PyExc_TypeError,
108
+ "spec.name must be a string");
109
+ goto error;
110
+ }
111
112
name = get_encoded_name(name_unicode, &hook_prefix);
113
if (name == NULL) {
0 commit comments