diff Python/import.c @ 37473:20ffc2ca03e0 legacy-trunk

Fix __import__("") to raise ValueError rather than return None.
author Thomas Wouters <thomas@python.org>
date Tue, 04 Apr 2006 16:17:02 +0000
parents c844305aa8ed
children 4b761a63399c
line wrap: on
line diff
--- a/Python/import.c	Tue Apr 04 15:52:00 2006 +0000
+++ b/Python/import.c	Tue Apr 04 16:17:02 2006 +0000
@@ -1934,6 +1934,14 @@
 		}
 		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 @@
 	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;