From: Eric Allman Date: Fri, 3 Dec 1993 02:17:57 +0000 (-0800) Subject: fix bogus implementation of name overflow limiting X-Git-Tag: BSD-4_4_Lite1-Snapshot-Development~1351 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/77779257a82dea6995ae40c34234905fc25304ad fix bogus implementation of name overflow limiting SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 8.29 SCCS-vsn: usr.sbin/sendmail/src/conf.h 8.57 SCCS-vsn: usr.sbin/sendmail/src/envelope.c 8.20 SCCS-vsn: usr.sbin/sendmail/src/parseaddr.c 8.20 SCCS-vsn: usr.sbin/sendmail/src/deliver.c 8.48 SCCS-vsn: usr.sbin/sendmail/src/util.c 8.20 --- diff --git a/usr/src/usr.sbin/sendmail/src/conf.h b/usr/src/usr.sbin/sendmail/src/conf.h index 93ebaf45fa..a58df6f23e 100644 --- a/usr/src/usr.sbin/sendmail/src/conf.h +++ b/usr/src/usr.sbin/sendmail/src/conf.h @@ -5,7 +5,7 @@ * * %sccs.include.redist.c% * - * @(#)conf.h 8.56 (Berkeley) %G% + * @(#)conf.h 8.57 (Berkeley) %G% */ /* @@ -38,7 +38,6 @@ # define MEMCHUNKSIZE 1024 /* chunk size for memory allocation */ # define MAXUSERENVIRON 100 /* max envars saved, must be >= 3 */ # define MAXALIASDB 12 /* max # of alias databases */ -# define PSBUFSIZE (MAXLINE + MAXATOM) /* size of prescan buffer */ # ifndef QUEUESIZE # define QUEUESIZE 1000 /* max # of jobs per queue run */ @@ -805,6 +804,13 @@ typedef void (*sigfunc_t) __P((int)); # define TOBUFSIZE (1024 - 256) #endif +/* +** Size of prescan buffer. +** Despite comments in the _sendmail_ book, this probably should +** not be changed; there are some hard-to-define dependencies. +*/ + +# define PSBUFSIZE (MAXNAME + MAXATOM) /* size of prescan buffer */ /* fork routine -- set above using #ifdef _osname_ or in Makefile */ # ifndef FORK # define FORK vfork /* function to call to fork mailer */ diff --git a/usr/src/usr.sbin/sendmail/src/deliver.c b/usr/src/usr.sbin/sendmail/src/deliver.c index 09c0a7ad1b..d25a190db3 100644 --- a/usr/src/usr.sbin/sendmail/src/deliver.c +++ b/usr/src/usr.sbin/sendmail/src/deliver.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)deliver.c 8.47 (Berkeley) %G%"; +static char sccsid[] = "@(#)deliver.c 8.48 (Berkeley) %G%"; #endif /* not lint */ #include "sendmail.h" @@ -1779,12 +1779,7 @@ logdelivery(m, mci, stat, ctladdr, e) if (ctladdr != NULL) { strcpy(bp, ", ctladdr="); - l = strlen(ctladdr->q_paddr); - if (l > 83) - sprintf(bp, "%.40s...%s", - ctladdr->q_paddr, ctladdr->q_paddr + l - 40); - else - strcat(bp, ctladdr->q_paddr); + strcpy(bp, shortenstring(ctladdr->q_paddr, 83)); bp += strlen(bp); if (bitset(QGOODUID, ctladdr->q_flags)) { diff --git a/usr/src/usr.sbin/sendmail/src/envelope.c b/usr/src/usr.sbin/sendmail/src/envelope.c index b7f7c784b0..0f4af92f2a 100644 --- a/usr/src/usr.sbin/sendmail/src/envelope.c +++ b/usr/src/usr.sbin/sendmail/src/envelope.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)envelope.c 8.19.1.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)envelope.c 8.20 (Berkeley) %G%"; #endif /* not lint */ #include "sendmail.h" @@ -605,7 +605,7 @@ setsender(from, e, delimptr, internal) } syslog(LOG_NOTICE, "setsender: %s: invalid or unparseable, received from %s", - from, p); + shortenstring(from, 83), p); } # endif /* LOG */ if (from != NULL) diff --git a/usr/src/usr.sbin/sendmail/src/parseaddr.c b/usr/src/usr.sbin/sendmail/src/parseaddr.c index c4624c7f91..3a7ffb06ea 100644 --- a/usr/src/usr.sbin/sendmail/src/parseaddr.c +++ b/usr/src/usr.sbin/sendmail/src/parseaddr.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)parseaddr.c 8.19 (Berkeley) %G%"; +static char sccsid[] = "@(#)parseaddr.c 8.20 (Berkeley) %G%"; #endif /* not lint */ #include "sendmail.h" @@ -103,14 +103,6 @@ parseaddr(addr, a, flags, delim, delimptr, e) if (delimptr == NULL) delimptr = &delimptrbuf; - if (strlen(addr) >= MAXNAME) - { - usrerr("Name too long, %d characters max", MAXNAME - 1); - if (tTd(20, 1)) - printf("parseaddr-->NULL\n"); - return NULL; - } - pvp = prescan(addr, delim, pvpbuf, delimptr); if (pvp == NULL) { @@ -442,6 +434,7 @@ prescan(addr, delim, pvpbuf, delimptr) if (q >= &pvpbuf[PSBUFSIZE - 5]) { usrerr("553 Address too long"); + returnnull: if (delimptr != NULL) *delimptr = p; CurEnv->e_to = saveto; @@ -587,10 +580,12 @@ prescan(addr, delim, pvpbuf, delimptr) if (avp >= &av[MAXATOM]) { syserr("553 prescan: too many tokens"); - if (delimptr != NULL) - *delimptr = p; - CurEnv->e_to = saveto; - return (NULL); + goto returnnull; + } + if (q - tok > MAXNAME) + { + syserr("553 prescan: token too long"); + goto returnnull; } *avp++ = tok; } diff --git a/usr/src/usr.sbin/sendmail/src/sendmail.h b/usr/src/usr.sbin/sendmail/src/sendmail.h index 9ab79a39ec..6354cce8de 100644 --- a/usr/src/usr.sbin/sendmail/src/sendmail.h +++ b/usr/src/usr.sbin/sendmail/src/sendmail.h @@ -5,7 +5,7 @@ * * %sccs.include.redist.c% * - * @(#)sendmail.h 8.28 (Berkeley) %G% + * @(#)sendmail.h 8.29 (Berkeley) %G% */ /* @@ -15,7 +15,7 @@ # ifdef _DEFINE # define EXTERN # ifndef lint -static char SmailSccsId[] = "@(#)sendmail.h 8.28 %G%"; +static char SmailSccsId[] = "@(#)sendmail.h 8.29 %G%"; # endif # else /* _DEFINE */ # define EXTERN extern @@ -930,6 +930,7 @@ extern char *hostsignature __P((MAILER *, char *, ENVELOPE *)); extern void openxscript __P((ENVELOPE *)); extern void closexscript __P((ENVELOPE *)); extern sigfunc_t setsignal __P((int, sigfunc_t)); +extern char *shortenstring __P((char *, int)); /* ellipsis is a different case though */ #ifdef __STDC__ diff --git a/usr/src/usr.sbin/sendmail/src/util.c b/usr/src/usr.sbin/sendmail/src/util.c index 5981107bf6..e06b0fac08 100644 --- a/usr/src/usr.sbin/sendmail/src/util.c +++ b/usr/src/usr.sbin/sendmail/src/util.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)util.c 8.19 (Berkeley) %G%"; +static char sccsid[] = "@(#)util.c 8.20 (Berkeley) %G%"; #endif /* not lint */ # include "sendmail.h" @@ -1347,3 +1347,52 @@ printit: else printf("%s\n", buf); } + /* +** SHORTENSTRING -- return short version of a string +** +** If the string is already short, just return it. If it is too +** long, return the head and tail of the string. +** +** Parameters: +** s -- the string to shorten. +** m -- the max length of the string. +** +** Returns: +** Either s or a short version of s. +*/ + +#ifndef MAXSHORTSTR +# define MAXSHORTSTR 83 +#endif + +char * +shortenstring(s, m) + register char *s; + int m; +{ + int l; + static char buf[MAXSHORTSTR + 1]; + + l = strlen(s); + if (l < m) + return s; + if (m > MAXSHORTSTR) + m = MAXSHORTSTR; + else if (m < 10) + { + if (m < 5) + { + strncpy(buf, s, m); + buf[m] = '\0'; + return buf; + } + strncpy(buf, s, m - 3); + strcpy(buf + m - 3, "..."); + return buf; + } + m = (m - 3) / 2; + strncpy(buf, s, m); + strcpy(buf + m, "..."); + strcpy(buf + m + 3, s + l - m); + return buf; +}