1
1

* edit.c (check_file_access): Use O_EXCL when opening new files.

Don't allow editing stale symlinks.
Reported by Max Derzhak <max@linux.zp.ua>
Этот коммит содержится в:
Pavel Roskin 2002-12-08 00:55:03 +00:00
родитель b64955fbbd
Коммит c3cdbeb001
2 изменённых файлов: 34 добавлений и 9 удалений

Просмотреть файл

@ -1,3 +1,9 @@
2002-12-07 Pavel Roskin <proski@gnu.org>
* edit.c (check_file_access): Use O_EXCL when opening new files.
Don't allow editing stale symlinks.
Reported by Max Derzhak <max@linux.zp.ua>
2002-12-05 Pavel Roskin <proski@gnu.org> 2002-12-05 Pavel Roskin <proski@gnu.org>
* edit-widget.h: Remove "from_here" and "to_here". * edit-widget.h: Remove "from_here" and "to_here".

Просмотреть файл

@ -315,9 +315,11 @@ int edit_insert_file (WEdit * edit, const char *filename)
} }
/* Open file and create it if necessary. Return 0 for success, 1 for error. */ /* Open file and create it if necessary. Return 0 for success, 1 for error. */
static int check_file_access (WEdit *edit, const char *filename, struct stat *st) static int
check_file_access (WEdit *edit, const char *filename, struct stat *st)
{ {
int file; int file;
int flags;
int stat_ok = 0; int stat_ok = 0;
/* Try stat first to prevent getting stuck on pipes */ /* Try stat first to prevent getting stuck on pipes */
@ -327,20 +329,34 @@ static int check_file_access (WEdit *edit, const char *filename, struct stat *st
/* Only regular files are allowed */ /* Only regular files are allowed */
if (stat_ok && !S_ISREG (st->st_mode)) { if (stat_ok && !S_ISREG (st->st_mode)) {
edit_error_dialog (_ ("Error"), catstrs (_ (" Not an ordinary file: "), filename, " ", 0)); edit_error_dialog (_("Error"),
catstrs (_(" Not an ordinary file: "), filename,
" ", 0));
return 1; return 1;
} }
/* Open the file, create it if needed */ /* Open the file, create it if (and only if!) needed */
if ((file = mc_open (filename, O_RDONLY | O_CREAT | O_BINARY, 0666)) < 0) { flags = O_RDONLY | O_CREAT | O_BINARY;
edit_error_dialog (_ ("Error"), get_sys_error (catstrs (_ (" Cannot open file for reading: "), filename, " ", 0))); if (!stat_ok)
flags |= O_EXCL;
if ((file = mc_open (filename, flags, 0666)) < 0) {
edit_error_dialog (_("Error"),
get_sys_error (catstrs
(_
(" Cannot open file for reading: "),
filename, " ", 0)));
return 1; return 1;
} }
/* If the file has just been created, we don't have valid stat yet, so do it now */ /* If the file has just been created, we don't have valid stat yet, so do it now */
if (!stat_ok && mc_fstat (file, st) < 0) { if (!stat_ok && mc_fstat (file, st) < 0) {
mc_close (file); mc_close (file);
edit_error_dialog (_ ("Error"), get_sys_error (catstrs (_ (" Cannot get size/permissions info for file: "), filename, " ", 0))); edit_error_dialog (_("Error"),
get_sys_error (catstrs
(_
(" Cannot get size/permissions info for file: "),
filename, " ", 0)));
return 1; return 1;
} }
mc_close (file); mc_close (file);
@ -351,9 +367,12 @@ static int check_file_access (WEdit *edit, const char *filename, struct stat *st
} }
if (st->st_size >= SIZE_LIMIT) { if (st->st_size >= SIZE_LIMIT) {
/* The file-name is printed after the ':' */ /* The file-name is printed after the ':' */
edit_error_dialog (_ ("Error"), catstrs (_ (" File is too large: "), \ edit_error_dialog (_("Error"),
filename, _ (" \n Increase edit.h:MAXBUF and recompile the editor. "), 0)); catstrs (_(" File is too large: "), filename,
_
(" \n Increase edit.h:MAXBUF and recompile the editor. "),
0));
return 1; return 1;
} }
return 0; return 0;