summaryrefslogtreecommitdiff
path: root/usr.bin/vi/common/exf.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/exf.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/exf.c')
-rw-r--r--usr.bin/vi/common/exf.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c
index 333c495d27f..d2b361d9f8b 100644
--- a/usr.bin/vi/common/exf.c
+++ b/usr.bin/vi/common/exf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exf.c,v 1.12 2001/01/29 01:58:29 niklas Exp $ */
+/* $OpenBSD: exf.c,v 1.13 2001/06/18 21:39:25 millert Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -189,9 +189,14 @@ file_init(sp, frp, rcv_name, flags)
goto err;
(void)snprintf(tname, sizeof(tname),
"%s/vi.XXXXXX", O_STR(sp, O_DIRECTORY));
- if ((fd = mkstemp(tname)) == -1) {
+ fd = mkstemp(tname);
+ if (fd == -1 || fchmod(fd, S_IRUSR | S_IWUSR) == -1) {
msgq(sp, M_SYSERR,
"237|Unable to create temporary file");
+ if (fd != -1) {
+ close(fd);
+ (void)unlink(tname);
+ }
goto err;
}
(void)close(fd);
@@ -1129,7 +1134,12 @@ file_backup(sp, name, bname)
flags = O_TRUNC;
} else
flags = O_CREAT | O_EXCL;
- if ((wfd = open(wfname, flags | O_WRONLY, S_IRUSR | S_IWUSR)) < 0) {
+ if ((wfd = open(wfname, flags | O_WRONLY, S_IRUSR | S_IWUSR)) < 0 ||
+ fchmod(wfd, S_IRUSR | S_IWUSR) < 0) {
+ if (wfd != -1) {
+ close(wfd);
+ (void)unlink(wfname);
+ }
estr = bname;
goto err;
}