summaryrefslogtreecommitdiffstats
path: root/bin/ed/buf.c
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>1997-03-24 05:45:29 +0000
committerimp <imp@FreeBSD.org>1997-03-24 05:45:29 +0000
commita1b85d31964b4b05633fde1702e549d831662bd4 (patch)
treeb3e066f8ac776d5d4aafab81ae8325d93f006d99 /bin/ed/buf.c
parent17787893f3501b922304307dc3e8bccde18b9742 (diff)
downloadFreeBSD-src-a1b85d31964b4b05633fde1702e549d831662bd4.zip
FreeBSD-src-a1b85d31964b4b05633fde1702e549d831662bd4.tar.gz
Use mkstemp rather than mktemp to prevent races.
Obtained from: OpenBSD
Diffstat (limited to 'bin/ed/buf.c')
-rw-r--r--bin/ed/buf.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/bin/ed/buf.c b/bin/ed/buf.c
index 5c6eded..567133a 100644
--- a/bin/ed/buf.c
+++ b/bin/ed/buf.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: buf.c,v 1.10 1997/02/22 14:03:11 peter Exp $
*/
#ifndef lint
static char * const rcsid = "@(#)buf.c,v 1.4 1994/02/01 00:34:35 alm Exp";
@@ -198,14 +198,18 @@ char sfn[15] = ""; /* scratch file name */
int
open_sbuf()
{
+ int fd = -1;
int u;
isbinary = newline_added = 0;
u = umask(077);
strcpy(sfn, "/tmp/ed.XXXXXX");
- if (mktemp(sfn) == NULL || (sfp = fopen(sfn, "w+")) == NULL) {
- fprintf(stderr, "%s: %s\n", sfn, strerror(errno));
- sprintf(errmsg, "cannot open temp file");
+ if ((fd = mkstemp(sfn)) == -1 ||
+ (sfp = fdopen(fd, "w+")) == NULL) {
+ if (fd != -1)
+ close(fd);
+ perror(sfn);
+ strcpy(errmsg, "cannot open temp file");
umask(u);
return ERR;
}
OpenPOWER on IntegriCloud