Use tempnam() to generate temporary file names instead of trying to

concatenate getenv("TMPDIR") and "RxXXXXXX" into fixed length arrays.
This commit is contained in:
jtc 1994-11-28 20:03:30 +00:00
parent 4bf773963e
commit b5508f3525
7 changed files with 31 additions and 47 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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