aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/mail/cmd3.c
diff options
context:
space:
mode:
authorMike Heffner <mikeh@FreeBSD.org>2001-03-25 04:57:05 +0000
committerMike Heffner <mikeh@FreeBSD.org>2001-03-25 04:57:05 +0000
commit0c3a8314c00f58f16823e8cd6186757d5e8bcdcc (patch)
treef39a12d6fff4adc1f80c5db2f64276c3dc45c30f /usr.bin/mail/cmd3.c
parentadad9908fa0babf8a4a972f0e62e1001ba5a5d34 (diff)
downloadsrc-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/cmd3.c')
-rw-r--r--usr.bin/mail/cmd3.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c
index 04cecf6a0b30..36e4267480d7 100644
--- a/usr.bin/mail/cmd3.c
+++ b/usr.bin/mail/cmd3.c
@@ -32,7 +32,11 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)cmd3.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$FreeBSD$";
#endif /* not lint */
#include "rcv.h"
@@ -56,8 +60,9 @@ shell(str)
char *shell;
char cmd[BUFSIZ];
- (void) strcpy(cmd, str);
- if (bangexp(cmd) < 0)
+ if (strlcpy(cmd, str, sizeof(cmd)) >= sizeof(cmd))
+ return 1;
+ if (bangexp(cmd, sizeof(cmd)) < 0)
return 1;
if ((shell = value("SHELL")) == NOSTR)
shell = _PATH_CSHELL;
@@ -90,21 +95,20 @@ dosh(str)
* Expand the shell escape by expanding unescaped !'s into the
* last issued command where possible.
*/
-
-char lastbang[128];
-
int
-bangexp(str)
+bangexp(str, strsize)
char *str;
+ size_t strsize;
{
char bangbuf[BUFSIZ];
+ static char lastbang[BUFSIZ];
register char *cp, *cp2;
register int n;
int changed = 0;
cp = str;
cp2 = bangbuf;
- n = BUFSIZ;
+ n = sizeof(bangbuf);
while (*cp) {
if (*cp == '!') {
if (n < strlen(lastbang)) {
@@ -113,7 +117,9 @@ overf:
return(-1);
}
changed++;
- strcpy(cp2, lastbang);
+ if (strlcpy(cp2, lastbang, sizeof(bangbuf) - (cp2 - bangbuf))
+ >= sizeof(bangbuf) - (cp2 - bangbuf))
+ goto overf;
cp2 += strlen(lastbang);
n -= strlen(lastbang);
cp++;
@@ -135,9 +141,10 @@ overf:
printf("!%s\n", bangbuf);
fflush(stdout);
}
- strcpy(str, bangbuf);
- strncpy(lastbang, bangbuf, 128);
- lastbang[127] = 0;
+ if (strlcpy(str, bangbuf, strsize) >= strsize)
+ goto overf;
+ if (strlcpy(lastbang, bangbuf, sizeof(lastbang)) >= sizeof(lastbang))
+ goto overf;
return(0);
}
@@ -152,7 +159,7 @@ help()
register FILE *f;
if ((f = Fopen(_PATH_HELP, "r")) == NULL) {
- perror(_PATH_HELP);
+ warn("%s", _PATH_HELP);
return(1);
}
while ((c = getc(f)) != EOF)
@@ -170,13 +177,15 @@ schdir(arglist)
{
char *cp;
- if (*arglist == NOSTR)
+ if (*arglist == NOSTR) {
+ if (homedir == NOSTR)
+ return(1);
cp = homedir;
- else
+ } else
if ((cp = expand(*arglist)) == NOSTR)
return(1);
if (chdir(cp) < 0) {
- perror(cp);
+ warn("%s", cp);
return(1);
}
return 0;
@@ -276,8 +285,7 @@ reedit(subj)
subj[2] == ':')
return subj;
newsubj = salloc(strlen(subj) + 5);
- strcpy(newsubj, "Re: ");
- strcpy(newsubj + 4, subj);
+ sprintf(newsubj, "Re: %s", subj);
return newsubj;
}
@@ -386,7 +394,7 @@ set(arglist)
for (ap = arglist; *ap != NOSTR; ap++) {
cp = *ap;
cp2 = varbuf;
- while (*cp != '=' && *cp != '\0')
+ while (cp2 < varbuf + sizeof(varbuf) - 1 && *cp != '=' && *cp != '\0')
*cp2++ = *cp++;
*cp2 = '\0';
if (*cp == '\0')