check readonly by trying to open the file for writing...

instead of mch_access, to avoid a possible race condition
This commit is contained in:
Stefan Hoffmann 2014-03-16 12:34:48 +01:00 committed by Thiago de Arruda
parent 23ee78a093
commit 4a138137f7

View File

@ -475,21 +475,11 @@ readfile (
} }
/* /*
* for UNIX: check readonly with perm and mch_access() * check readonly by trying to open the file for writing
* for MSDOS and Amiga: check readonly by trying to open the file for writing
*/ */
file_readonly = FALSE; file_readonly = FALSE;
if (read_stdin) { if (read_stdin) {
} else if (!read_buffer) { } else if (!read_buffer) {
#ifdef USE_MCH_ACCESS
if (
# ifdef UNIX
!(perm & 0222) ||
# endif
mch_access((char *)fname, W_OK))
file_readonly = TRUE;
fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
#else
if (!newfile if (!newfile
|| readonlymode || readonlymode
|| (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0) { || (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0) {
@ -497,7 +487,6 @@ readfile (
/* try to open ro */ /* try to open ro */
fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
} }
#endif
} }
if (fd < 0) { /* cannot open at all */ if (fd < 0) { /* cannot open at all */