summaryrefslogtreecommitdiff
path: root/usr.bin/vi/common/recover.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-06-18 21:39:27 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-06-18 21:39:27 +0000
commit1c4e6cd26420fee6e835171ffffb3b8b1e6dc3cd (patch)
treebd74a103f58a556a1b4c2091fd4d16b566267cc7 /usr.bin/vi/common/recover.c
parent36a1298f5bf20a09cb892234b987be86a778120b (diff)
When creating temp files, use fchmod() to set the perms to be what we
expect since the mode mkstemp() uses can be modified by the umask. This fixes a problem where vi would spin trying to create temp files, eating up inodes; reported by xyntrix@bitz.org This fix has the side effect of letting you create files with silly modes (like 0000), but that is probably OK.
Diffstat (limited to 'usr.bin/vi/common/recover.c')
-rw-r--r--usr.bin/vi/common/recover.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/usr.bin/vi/common/recover.c b/usr.bin/vi/common/recover.c
index a61685dd2b2..2b47562da48 100644
--- a/usr.bin/vi/common/recover.c
+++ b/usr.bin/vi/common/recover.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: recover.c,v 1.6 2001/05/28 22:41:35 pvalchev Exp $ */
+/* $OpenBSD: recover.c,v 1.7 2001/06/18 21:39:26 millert Exp $ */
/*-
* Copyright (c) 1993, 1994
@@ -837,16 +837,19 @@ rcv_mktemp(sp, path, dname, perms)
* !!!
* We expect mkstemp(3) to set the permissions correctly. On
* historic System V systems, mkstemp didn't. Do it here, on
- * GP's.
+ * GP's. This also protects us from users with stupid umasks.
*
* XXX
- * The variable perms should really be a mode_t, and it would
- * be nice to use fchmod(2) instead of chmod(2), here.
+ * The variable perms should really be a mode_t.
*/
- if ((fd = mkstemp(path)) == -1)
+ if ((fd = mkstemp(path)) == -1 || fchmod(fd, perms) == -1) {
msgq_str(sp, M_SYSERR, dname, "%s");
- else
- (void)chmod(path, perms);
+ if (fd != -1) {
+ close(fd);
+ unlink(path);
+ fd = -1;
+ }
+ }
return (fd);
}