Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
On systems that open() a regular file with a trailing slash as ENOTDIR
patch by Michael Felt
19 changes: 19 additions & 0 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,25 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
}
}
else {
#if defined(S_ISREG) && defined(ENOTDIR)
/* On AIX and Windows, open() may succeed for files with a trailing slash.
The Open Group specifies filenames ending with a trailing slash should
be an error - ENOTDIR */
if (fd < 0 && S_ISREG(fdfstat.st_mode)) {
#ifdef MS_WINDOWS
size_t len = wcslen(widename);
if (len && (widename[len - 1] == L'\\' ||
widename[len - 1] == L'/')) {
#else
size_t len = strlen(name);
if (len && name[len - 1] == '/') {
#endif
errno = ENOTDIR;
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj);
goto error;
}
}
#endif
#if defined(S_ISDIR) && defined(EISDIR)
/* On Unix, open will succeed for directories.
In Python, there should be no file objects referring to
Expand Down