From b5508f3525d2cb5e9ae12457fbf468f13d21870b Mon Sep 17 00:00:00 2001 From: jtc Date: Mon, 28 Nov 1994 20:03:30 +0000 Subject: [PATCH] Use tempnam() to generate temporary file names instead of trying to concatenate getenv("TMPDIR") and "RxXXXXXX" into fixed length arrays. --- usr.bin/mail/collect.c | 8 ++++---- usr.bin/mail/edit.c | 4 ++-- usr.bin/mail/lex.c | 4 ++-- usr.bin/mail/names.c | 4 ++-- usr.bin/mail/quit.c | 13 ++++++------- usr.bin/mail/send.c | 4 ++-- usr.bin/mail/temp.c | 41 +++++++++++++---------------------------- 7 files changed, 31 insertions(+), 47 deletions(-) diff --git a/usr.bin/mail/collect.c b/usr.bin/mail/collect.c index f25ba620f8e2..b2204eba9d26 100644 --- a/usr.bin/mail/collect.c +++ b/usr.bin/mail/collect.c @@ -33,7 +33,7 @@ #ifndef lint static char sccsid[] = "from: @(#)collect.c 8.2 (Berkeley) 4/19/94"; -static char rcsid[] = "$Id: collect.c,v 1.3 1994/06/29 05:09:14 deraadt Exp $"; +static char rcsid[] = "$Id: collect.c,v 1.4 1994/11/28 20:03:30 jtc Exp $"; #endif /* not lint */ /* @@ -78,7 +78,7 @@ collect(hp, printheaders) int lc, cc, escape, eofcount; register int c, t; char linebuf[LINESIZE], *cp; - extern char tempMail[]; + extern char *tempMail; char getsub; int omask; void collint(), collhup(), collstop(); @@ -464,7 +464,7 @@ mespipe(fp, cmd) { FILE *nf; sig_t sigint = signal(SIGINT, SIG_IGN); - extern char tempEdit[]; + extern char *tempEdit; char *shell; if ((nf = Fopen(tempEdit, "w+")) == NULL) { @@ -513,7 +513,7 @@ forward(ms, fp, f) int f; { register int *msgvec; - extern char tempMail[]; + extern char *tempMail; struct ignoretab *ig; char *tabst; diff --git a/usr.bin/mail/edit.c b/usr.bin/mail/edit.c index 809c9321c9d0..f5d11fd6bc3e 100644 --- a/usr.bin/mail/edit.c +++ b/usr.bin/mail/edit.c @@ -33,7 +33,7 @@ #ifndef lint static char sccsid[] = "from: @(#)edit.c 8.1 (Berkeley) 6/6/93"; -static char rcsid[] = "$Id: edit.c,v 1.3 1994/06/29 05:09:17 deraadt Exp $"; +static char rcsid[] = "$Id: edit.c,v 1.4 1994/11/28 20:03:32 jtc Exp $"; #endif /* not lint */ #include "rcv.h" @@ -149,7 +149,7 @@ run_editor(fp, size, type, readonly) time_t modtime; char *edit; struct stat statb; - extern char tempEdit[]; + extern char *tempEdit; if ((t = creat(tempEdit, readonly ? 0400 : 0600)) < 0) { perror(tempEdit); diff --git a/usr.bin/mail/lex.c b/usr.bin/mail/lex.c index 9d5f965dbac1..25bd4f2e21e7 100644 --- a/usr.bin/mail/lex.c +++ b/usr.bin/mail/lex.c @@ -33,7 +33,7 @@ #ifndef lint static char sccsid[] = "from: @(#)lex.c 8.1 (Berkeley) 6/6/93"; -static char rcsid[] = "$Id: lex.c,v 1.4 1994/06/29 05:09:28 deraadt Exp $"; +static char rcsid[] = "$Id: lex.c,v 1.5 1994/11/28 20:03:33 jtc Exp $"; #endif /* not lint */ #include "rcv.h" @@ -65,7 +65,7 @@ setfile(name) char isedit = *name != '%'; char *who = name[1] ? name + 1 : myname; static int shudclob; - extern char tempMesg[]; + extern char *tempMesg; extern int errno; if ((name = expand(name)) == NOSTR) diff --git a/usr.bin/mail/names.c b/usr.bin/mail/names.c index 671b4bde1cfa..a5d9dcbad3ba 100644 --- a/usr.bin/mail/names.c +++ b/usr.bin/mail/names.c @@ -33,7 +33,7 @@ #ifndef lint static char sccsid[] = "from: @(#)names.c 8.1 (Berkeley) 6/6/93"; -static char rcsid[] = "$Id: names.c,v 1.3 1994/06/29 05:09:35 deraadt Exp $"; +static char rcsid[] = "$Id: names.c,v 1.4 1994/11/28 20:03:34 jtc Exp $"; #endif /* not lint */ /* @@ -224,7 +224,7 @@ outof(names, fo, hp) char *date, *fname, *ctime(); FILE *fout, *fin; int ispipe; - extern char tempEdit[]; + extern char *tempEdit; top = names; np = names; diff --git a/usr.bin/mail/quit.c b/usr.bin/mail/quit.c index 85dedb64b52c..e55a66d9ad30 100644 --- a/usr.bin/mail/quit.c +++ b/usr.bin/mail/quit.c @@ -33,7 +33,7 @@ #ifndef lint static char sccsid[] = "from: @(#)quit.c 8.1 (Berkeley) 6/6/93"; -static char rcsid[] = "$Id: quit.c,v 1.3 1994/06/29 05:09:39 deraadt Exp $"; +static char rcsid[] = "$Id: quit.c,v 1.4 1994/11/28 20:03:37 jtc Exp $"; #endif /* not lint */ #include "rcv.h" @@ -73,7 +73,7 @@ quit() FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf; register struct message *mp; register int c; - extern char tempQuit[], tempResid[]; + extern char *tempQuit, *tempResid; struct stat minfo; char *mbox; @@ -390,8 +390,7 @@ edstop() register struct message *mp; FILE *obuf, *ibuf, *readstat; struct stat statb; - char tempname[30]; - char *mktemp(); + char *tempname; if (readonly) return; @@ -420,9 +419,8 @@ edstop() goto done; ibuf = NULL; if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) { - strcpy(tempname, tmpdir); - strcat(tempname, "mboxXXXXXX"); - mktemp(tempname); + tempname = tempnam(tmpdir, "mbox"); + if ((obuf = Fopen(tempname, "w")) == NULL) { perror(tempname); relsesigs(); @@ -447,6 +445,7 @@ edstop() reset(0); } rm(tempname); + free(tempname); } printf("\"%s\" ", mailname); fflush(stdout); diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index 6fadeeb74057..2a21a3be66c6 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -33,7 +33,7 @@ #ifndef lint static char sccsid[] = "from: @(#)send.c 8.1 (Berkeley) 6/6/93"; -static char rcsid[] = "$Id: send.c,v 1.4 1994/06/29 05:09:42 deraadt Exp $"; +static char rcsid[] = "$Id: send.c,v 1.5 1994/11/28 20:03:38 jtc Exp $"; #endif /* not lint */ #include "rcv.h" @@ -427,7 +427,7 @@ infix(hp, fi) struct header *hp; FILE *fi; { - extern char tempMail[]; + extern char *tempMail; register FILE *nfo, *nfi; register int c; diff --git a/usr.bin/mail/temp.c b/usr.bin/mail/temp.c index 952cff3a493c..10b584c6f53f 100644 --- a/usr.bin/mail/temp.c +++ b/usr.bin/mail/temp.c @@ -33,7 +33,7 @@ #ifndef lint static char sccsid[] = "from: @(#)temp.c 8.1 (Berkeley) 6/6/93"; -static char rcsid[] = "$Id: temp.c,v 1.3 1994/06/29 05:09:45 deraadt Exp $"; +static char rcsid[] = "$Id: temp.c,v 1.4 1994/11/28 20:03:40 jtc Exp $"; #endif /* not lint */ #include "rcv.h" @@ -46,11 +46,11 @@ static char rcsid[] = "$Id: temp.c,v 1.3 1994/06/29 05:09:45 deraadt Exp $"; * Give names to all the temporary files that we will need. */ -char tempMail[24]; -char tempQuit[24]; -char tempEdit[24]; -char tempResid[24]; -char tempMesg[24]; +char *tempMail; +char *tempQuit; +char *tempEdit; +char *tempResid; +char *tempMesg; char *tmpdir; void @@ -59,30 +59,15 @@ tinit() register char *cp; int len; - if ((tmpdir = getenv("TMPDIR")) == NULL) + if ((tmpdir = getenv("TMPDIR")) == NULL) { tmpdir = _PATH_TMP; - else { - len = strlen(tmpdir); - if ((cp = malloc(len + 2)) == NULL) { - (void)fprintf(stderr, "mail: %s\n", strerror(errno)); - exit (1); - } - (void)strcpy(cp, tmpdir); - cp[len] = '/'; - cp[len + 1] = '\0'; - tmpdir = cp; } - - strcpy(tempMail, tmpdir); - mktemp(strcat(tempMail, "RsXXXXXX")); - strcpy(tempResid, tmpdir); - mktemp(strcat(tempResid, "RqXXXXXX")); - strcpy(tempQuit, tmpdir); - mktemp(strcat(tempQuit, "RmXXXXXX")); - strcpy(tempEdit, tmpdir); - mktemp(strcat(tempEdit, "ReXXXXXX")); - strcpy(tempMesg, tmpdir); - mktemp(strcat(tempMesg, "RxXXXXXX")); + + tempMail = tempnam (tmpdir, "Rs"); + tempResid = tempnam (tmpdir, "Rq"); + tempQuit = tempnam (tmpdir, "Rm"); + tempEdit = tempnam (tmpdir, "Re"); + tempMesg = tempnam (tmpdir, "Rx"); /* * It's okay to call savestr in here because main will