Okay last time, now if there's any file at all, dont save the .save file. (foolproof? :)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@368 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2000-12-03 03:01:12 +00:00
parent d7ad75adb3
commit 581bc60d0c
3 changed files with 7 additions and 9 deletions

View File

@ -23,8 +23,7 @@ CVS code -
- files.c: - files.c:
write_file() write_file()
- Unsetting modified on temp files bug fixed (Rocco Corsi). - Unsetting modified on temp files bug fixed (Rocco Corsi).
- Okay, if tmp == 1 and the file is a symlink the user doesn't - Okay, if tmp == 1 and the file exists, we abort.
own, we return -1.
do_insertfile() do_insertfile()
- Added call to real_name_from tilde, oops. Added check for - Added call to real_name_from tilde, oops. Added check for
DISABLE_TABCOMP. DISABLE_TABCOMP.
@ -66,7 +65,7 @@ CVS code -
die() die()
- Now creates .save file using variable-length strings. Also - Now creates .save file using variable-length strings. Also
calls write_file with tmp == 1, which happens to do exactly what calls write_file with tmp == 1, which happens to do exactly what
we want (abort on save file is a symlink and use mode 0600). we want (abort on save file exists and use mode 0600).
handle_sighup() handle_sighup()
- Now calls die instead of writing on its own and exiting normally. - Now calls die instead of writing on its own and exiting normally.
- search.c: - search.c:

View File

@ -321,7 +321,6 @@ int write_file(char *name, int tmp)
realname = mallocstrcpy(realname, name); realname = mallocstrcpy(realname, name);
#endif #endif
/* Save the state of file at the end of the symlink */ /* Save the state of file at the end of the symlink */
realexists = stat(realname, &st); realexists = stat(realname, &st);
@ -330,9 +329,9 @@ int write_file(char *name, int tmp)
cause unexpected behavior */ cause unexpected behavior */
lstat(realname, &st); lstat(realname, &st);
/* New case: if it's a symlink and tmp is set AND the user does not /* New case: if the file exists, just give up. Easy way out of
own the symlink, abort. It could be a symlink attack */ all security issues */
if (tmp && S_ISLNK(st.st_mode) && getuid() != st.st_uid) if (tmp && realexists != -1)
return -1; return -1;
else if (ISSET(FOLLOW_SYMLINKS) || !S_ISLNK(st.st_mode)) { else if (ISSET(FOLLOW_SYMLINKS) || !S_ISLNK(st.st_mode)) {
@ -430,7 +429,7 @@ int write_file(char *name, int tmp)
} else { } else {
/* Use permissions from file we are overwriting. */ /* Use permissions from file we are overwriting. */
mask = st.st_mode; mask = st.st_mode;
if (!tmp && unlink(realname) == -1) { if (unlink(realname) == -1) {
if (errno != ENOENT) { if (errno != ENOENT) {
statusbar(_("Could not open %s for writing: %s"), statusbar(_("Could not open %s for writing: %s"),
realname, strerror(errno)); realname, strerror(errno));

2
nano.c
View File

@ -136,7 +136,7 @@ void die(char *msg, ...)
if (i != -1) if (i != -1)
fprintf(stderr, _("\nBuffer written to %s\n"), name); fprintf(stderr, _("\nBuffer written to %s\n"), name);
else else
fprintf(stderr, _("\nNo .save file written (symlink encountered?)\n")); fprintf(stderr, _("\nNo .save file written (file exists?)\n"));
exit(1); /* We have a problem: exit w/ errorlevel(1) */ exit(1); /* We have a problem: exit w/ errorlevel(1) */
} }