diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-09-23 16:54:40 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-09-23 16:54:40 (GMT) |
commit | 53ffdc53bf0500e402682d1459a9a8d06573664c (patch) | |
tree | 8a31a9cea84833742ff378c663d5854dfe158746 /Python | |
parent | da6eb5305fabdf4a4dd48c010724bcdf962d1612 (diff) | |
download | cpython-53ffdc53bf0500e402682d1459a9a8d06573664c.zip cpython-53ffdc53bf0500e402682d1459a9a8d06573664c.tar.gz cpython-53ffdc53bf0500e402682d1459a9a8d06573664c.tar.bz2 |
Issue #7732: Don't open a directory as a file anymore while importing a
module. Ignore the direcotry if its name matchs the module name (e.g.
"__init__.py") and raise a ImportError instead.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c index ee905eb..2adcb04 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1763,6 +1763,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, saved_namelen = namelen; #endif /* PYOS_OS2 */ for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { + struct stat statbuf; #if defined(PYOS_OS2) && defined(HAVE_DYNAMIC_LOADING) /* OS/2 limits DLLs to 8 character names (w/o extension) @@ -1791,10 +1792,16 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, strcpy(buf+len, fdp->suffix); if (Py_VerboseFlag > 1) PySys_WriteStderr("# trying %s\n", buf); + filemode = fdp->mode; if (filemode[0] == 'U') filemode = "r" PY_STDIOTEXTMODE; - fp = fopen(buf, filemode); + + if (stat(buf, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) + /* it's a directory */ + fp = NULL; + else + fp = fopen(buf, filemode); if (fp != NULL) { if (case_ok(buf, len, namelen, name)) break; |