diff options
author | Thomas Wouters <thomas@python.org> | 2006-04-04 16:17:02 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2006-04-04 16:17:02 (GMT) |
commit | 8ddab27182d7d00f32f423955d2344b8ba40b9d7 (patch) | |
tree | 3ab068255de9c67b7fb88afd04a36ff1aabb8848 /Python | |
parent | 06853fc15055686ec02fd2671fd37cda0f69209b (diff) | |
download | cpython-8ddab27182d7d00f32f423955d2344b8ba40b9d7.zip cpython-8ddab27182d7d00f32f423955d2344b8ba40b9d7.tar.gz cpython-8ddab27182d7d00f32f423955d2344b8ba40b9d7.tar.bz2 |
Fix __import__("") to raise ValueError rather than return None.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c index 9d63891..6a47d95 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1934,6 +1934,14 @@ import_module_level(char *name, PyObject *globals, PyObject *locals, } tail = next; } + if (tail == Py_None) { + /* If tail is Py_None, both get_parent and load_next found + an empty module name: someone called __import__("") or + doctored faulty bytecode */ + PyErr_SetString(PyExc_ValueError, + "Empty module name"); + return NULL; + } if (fromlist != NULL) { if (fromlist == Py_None || !PyObject_IsTrue(fromlist)) @@ -2094,7 +2102,8 @@ load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf, PyObject *result; if (strlen(name) == 0) { - /* empty module name only happens in 'from . import' */ + /* completely empty module name should only happen in + 'from . import' (or '__import__("")')*/ Py_INCREF(mod); *p_name = NULL; return mod; |