diff options
author | Mike Heffner <mikeh@FreeBSD.org> | 2001-03-25 04:57:05 +0000 |
---|---|---|
committer | Mike Heffner <mikeh@FreeBSD.org> | 2001-03-25 04:57:05 +0000 |
commit | 0c3a8314c00f58f16823e8cd6186757d5e8bcdcc (patch) | |
tree | f39a12d6fff4adc1f80c5db2f64276c3dc45c30f /usr.bin/mail/lex.c | |
parent | adad9908fa0babf8a4a972f0e62e1001ba5a5d34 (diff) | |
download | src-0c3a8314c00f58f16823e8cd6186757d5e8bcdcc.tar.gz src-0c3a8314c00f58f16823e8cd6186757d5e8bcdcc.zip |
Merge various changes from OpenBSD and NetBSD.
o remove panic() in favor of err(3) and use err(3) functions
consistently throughout
o use stat(2)'s S_IS* macros rather than S_IF*
o [r]index -> str[r]chr
o convert some static buffers to dynamic ones
o use real tempfiles rather than reopening the same templates
o rename some functions that clash with libc
o convert wait_status from union to int and use wait(2) status macros
o fix multiple potential buffer overflows
o fix a few comments
o add $FreeBSD$
Reviewed by: nra, nectar (earlier version)
Notes
Notes:
svn path=/head/; revision=74769
Diffstat (limited to 'usr.bin/mail/lex.c')
-rw-r--r-- | usr.bin/mail/lex.c | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/usr.bin/mail/lex.c b/usr.bin/mail/lex.c index c80b46b11410..6f89a6978d04 100644 --- a/usr.bin/mail/lex.c +++ b/usr.bin/mail/lex.c @@ -34,7 +34,11 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)lex.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$FreeBSD$"; #endif /* not lint */ #include "rcv.h" @@ -61,12 +65,12 @@ setfile(name) char *name; { FILE *ibuf; - int i; + int i, fd; struct stat stb; char isedit = *name != '%'; char *who = name[1] ? name + 1 : myname; + char tempname[PATHSIZE]; static int shudclob; - extern char *tempMesg; if ((name = expand(name)) == NOSTR) return -1; @@ -74,30 +78,20 @@ setfile(name) if ((ibuf = Fopen(name, "r")) == NULL) { if (!isedit && errno == ENOENT) goto nomail; - perror(name); + warn("%s", name); return(-1); } if (fstat(fileno(ibuf), &stb) < 0) { - perror("fstat"); + warn("fstat"); Fclose(ibuf); return (-1); } - switch (stb.st_mode & S_IFMT) { - case S_IFDIR: + if (S_ISDIR(stb.st_mode) || !S_ISREG(stb.st_mode)) { Fclose(ibuf); - errno = EISDIR; - perror(name); - return (-1); - - case S_IFREG: - break; - - default: - Fclose(ibuf); - errno = EINVAL; - perror(name); + errno = S_ISDIR(stb.st_mode) ? EISDIR : EINVAL; + warn("%s", name); return (-1); } @@ -128,21 +122,18 @@ setfile(name) } shudclob = 1; edit = isedit; - strcpy(prevfile, mailname); + strlcpy(prevfile, mailname, sizeof(prevfile)); if (name != mailname) - strcpy(mailname, name); + strlcpy(mailname, name, sizeof(mailname)); mailsize = fsize(ibuf); - if ((otf = fopen(tempMesg, "w")) == NULL) { - perror(tempMesg); - exit(1); - } + snprintf(tempname, sizeof(tempname), "%s/mail.RxXXXXXXXXXX", tmpdir); + if ((fd = mkstemp(tempname)) == -1 || (otf = fdopen(fd, "w")) == NULL) + err(1, "%s", tempname); (void) fcntl(fileno(otf), F_SETFD, 1); - if ((itf = fopen(tempMesg, "r")) == NULL) { - perror(tempMesg); - exit(1); - } + if ((itf = fopen(tempname, "r")) == NULL) + err(1, "%s", tempname); (void) fcntl(fileno(itf), F_SETFD, 1); - rm(tempMesg); + rm(tempname); setptr(ibuf); setmsize(msgCount); Fclose(ibuf); @@ -273,7 +264,7 @@ execute(linebuf, contxt) return(0); } cp2 = word; - while (*cp && index(" \t0123456789$^.:/-+*'\"", *cp) == NOSTR) + while (*cp && strchr(" \t0123456789$^.:/-+*'\"", *cp) == NOSTR) *cp2++ = *cp++; *cp2 = '\0'; @@ -405,7 +396,7 @@ execute(linebuf, contxt) break; default: - panic("Unknown argtype"); + errx(1, "Unknown argtype"); } out: @@ -463,7 +454,7 @@ lex(word) * ignore trailing chars after `#' * * lines with beginning `#' are comments - * spaces befor `#' are ignored in execute() + * spaces before `#' are ignored in execute() */ if (*word == '#') @@ -588,7 +579,7 @@ newfileinfo() { register struct message *mp; register int u, n, mdot, d, s; - char fname[BUFSIZ], zname[BUFSIZ], *ename; + char fname[PATHSIZE+1], zname[PATHSIZE+1], *ename; for (mp = &message[0]; mp < &message[msgCount]; mp++) if (mp->m_flag & MNEW) @@ -613,10 +604,10 @@ newfileinfo() s++; } ename = mailname; - if (getfold(fname) >= 0) { + if (getfold(fname, sizeof(fname) - 1) >= 0) { strcat(fname, "/"); if (strncmp(fname, mailname, strlen(fname)) == 0) { - sprintf(zname, "+%s", mailname + strlen(fname)); + snprintf(zname, sizeof(zname), "+%s", mailname + strlen(fname)); ename = zname; } } |