From a1b85d31964b4b05633fde1702e549d831662bd4 Mon Sep 17 00:00:00 2001 From: imp Date: Mon, 24 Mar 1997 05:45:29 +0000 Subject: Use mkstemp rather than mktemp to prevent races. Obtained from: OpenBSD --- bin/ed/buf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'bin/ed') 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; } -- cgit v1.1