From: Eric Allman Date: Wed, 15 Mar 1995 01:11:22 +0000 (-0800) Subject: change call to expand() to be more rational (and consistent!) X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/832e8a277c2e2f550d421e1583ef6f5af424e6fe change call to expand() to be more rational (and consistent!) SCCS-vsn: usr.sbin/sendmail/src/usersmtp.c 8.38 SCCS-vsn: usr.sbin/sendmail/src/headers.c 8.50 SCCS-vsn: usr.sbin/sendmail/src/macro.c 8.10 SCCS-vsn: usr.sbin/sendmail/src/main.c 8.91 SCCS-vsn: usr.sbin/sendmail/src/envelope.c 8.52 SCCS-vsn: usr.sbin/sendmail/src/parseaddr.c 8.58 SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 8.103 SCCS-vsn: usr.sbin/sendmail/src/savemail.c 8.56 SCCS-vsn: usr.sbin/sendmail/src/daemon.c 8.74 SCCS-vsn: usr.sbin/sendmail/src/srvrsmtp.c 8.56 SCCS-vsn: usr.sbin/sendmail/src/readcf.c 8.74 SCCS-vsn: usr.sbin/sendmail/src/deliver.c 8.130 SCCS-vsn: usr.sbin/sendmail/src/queue.c 8.68 SCCS-vsn: usr.sbin/sendmail/src/alias.c 8.39 --- diff --git a/usr/src/usr.sbin/sendmail/src/alias.c b/usr/src/usr.sbin/sendmail/src/alias.c index 7dc0e965a1..ff6f37a906 100644 --- a/usr/src/usr.sbin/sendmail/src/alias.c +++ b/usr/src/usr.sbin/sendmail/src/alias.c @@ -10,7 +10,7 @@ # include #ifndef lint -static char sccsid[] = "@(#)alias.c 8.38 (Berkeley) %G%"; +static char sccsid[] = "@(#)alias.c 8.39 (Berkeley) %G%"; #endif /* not lint */ @@ -808,7 +808,7 @@ forward(user, sendq, aliaslevel, e) ep = strchr(pp, ':'); if (ep != NULL) *ep = '\0'; - expand(pp, buf, &buf[sizeof buf - 1], e); + expand(pp, buf, sizeof buf, e); if (ep != NULL) *ep++ = ':'; if (tTd(27, 3)) diff --git a/usr/src/usr.sbin/sendmail/src/daemon.c b/usr/src/usr.sbin/sendmail/src/daemon.c index e90a7f4530..938070791e 100644 --- a/usr/src/usr.sbin/sendmail/src/daemon.c +++ b/usr/src/usr.sbin/sendmail/src/daemon.c @@ -12,9 +12,9 @@ #ifndef lint #ifdef DAEMON -static char sccsid[] = "@(#)daemon.c 8.73 (Berkeley) %G% (with daemon mode)"; +static char sccsid[] = "@(#)daemon.c 8.74 (Berkeley) %G% (with daemon mode)"; #else -static char sccsid[] = "@(#)daemon.c 8.73 (Berkeley) %G% (without daemon mode)"; +static char sccsid[] = "@(#)daemon.c 8.74 (Berkeley) %G% (without daemon mode)"; #endif #endif /* not lint */ @@ -148,7 +148,7 @@ getrequests() { char jbuf[MAXHOSTNAMELEN]; - expand("\201j", jbuf, &jbuf[sizeof jbuf - 1], CurEnv); + expand("\201j", jbuf, sizeof jbuf, CurEnv); j_has_dot = strchr(jbuf, '.') != NULL; } #endif diff --git a/usr/src/usr.sbin/sendmail/src/deliver.c b/usr/src/usr.sbin/sendmail/src/deliver.c index aaa8704ad7..831fe2cb49 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.129 (Berkeley) %G%"; +static char sccsid[] = "@(#)deliver.c 8.130 (Berkeley) %G%"; #endif /* not lint */ #include "sendmail.h" @@ -752,7 +752,7 @@ deliver(e, firstto) break; /* this entry is safe -- go ahead and process it */ - expand(*mvp, buf, &buf[sizeof buf], e); + expand(*mvp, buf, sizeof buf, e); *pvp++ = newstr(buf); if (pvp >= &pv[MAXPV - 3]) { @@ -938,7 +938,7 @@ deliver(e, firstto) if (!clever) { - expand(*mvp, buf, &buf[sizeof buf], e); + expand(*mvp, buf, sizeof buf, e); *pvp++ = newstr(buf); if (pvp >= &pv[MAXPV - 2]) { @@ -964,7 +964,7 @@ deliver(e, firstto) while (!clever && *++mvp != NULL) { - expand(*mvp, buf, &buf[sizeof buf], e); + expand(*mvp, buf, sizeof buf, e); *pvp++ = newstr(buf); if (pvp >= &pv[MAXPV]) syserr("554 deliver: pv overflow after $u for %s", pv[0]); @@ -1300,7 +1300,7 @@ tryhost: q = strchr(p, ':'); if (q != NULL) *q = '\0'; - expand(p, buf, &buf[sizeof buf], e); + expand(p, buf, sizeof buf, e); if (q != NULL) *q++ = ':'; if (tTd(11, 20)) @@ -2195,7 +2195,7 @@ putfromline(mci, e) char *bang; char xbuf[MAXLINE]; - expand("\201g", buf, &buf[sizeof buf - 1], e); + expand("\201g", buf, sizeof buf, e); bang = strchr(buf, '!'); if (bang == NULL) { @@ -2210,7 +2210,7 @@ putfromline(mci, e) } } # endif /* UGLYUUCP */ - expand(template, buf, &buf[sizeof buf - 1], e); + expand(template, buf, sizeof buf, e); putxline(buf, mci, FALSE); } /* diff --git a/usr/src/usr.sbin/sendmail/src/envelope.c b/usr/src/usr.sbin/sendmail/src/envelope.c index 022c678035..c0ad199447 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.51 (Berkeley) %G%"; +static char sccsid[] = "@(#)envelope.c 8.52 (Berkeley) %G%"; #endif /* not lint */ #include "sendmail.h" @@ -686,7 +686,7 @@ setsender(from, e, delimptr, internal) char nbuf[100]; SuprErrs = TRUE; - expand("\201n", nbuf, &nbuf[sizeof nbuf], e); + expand("\201n", nbuf, sizeof nbuf, e); if (parseaddr(from = newstr(nbuf), &e->e_from, RF_COPYALL, ' ', NULL, e) == NULL && parseaddr(from = "postmaster", &e->e_from, diff --git a/usr/src/usr.sbin/sendmail/src/headers.c b/usr/src/usr.sbin/sendmail/src/headers.c index ab6611522a..1e62d70a2f 100644 --- a/usr/src/usr.sbin/sendmail/src/headers.c +++ b/usr/src/usr.sbin/sendmail/src/headers.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)headers.c 8.49 (Berkeley) %G%"; +static char sccsid[] = "@(#)headers.c 8.50 (Berkeley) %G%"; #endif /* not lint */ # include @@ -164,7 +164,7 @@ chompheader(line, def, e) char *oldg = macvalue('g', e); define('g', p, e); - expand(fancy, buf, &buf[sizeof buf], e); + expand(fancy, buf, sizeof buf, e); define('g', oldg, e); fvalue = buf; } @@ -387,7 +387,7 @@ eatheader(e, full) /* do early binding */ if (bitset(H_DEFAULT, h->h_flags)) { - expand(h->h_value, buf, &buf[sizeof buf], e); + expand(h->h_value, buf, sizeof buf, e); if (buf[0] != '\0') { h->h_value = newstr(buf); @@ -1001,7 +1001,7 @@ putheader(mci, h, e) p = h->h_value; if (bitset(H_DEFAULT, h->h_flags)) { - expand(p, buf, &buf[sizeof buf], e); + expand(p, buf, sizeof buf, e); p = buf; if (p == NULL || *p == '\0') { diff --git a/usr/src/usr.sbin/sendmail/src/macro.c b/usr/src/usr.sbin/sendmail/src/macro.c index 6a3adc4d1d..3c017dfd2c 100644 --- a/usr/src/usr.sbin/sendmail/src/macro.c +++ b/usr/src/usr.sbin/sendmail/src/macro.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)macro.c 8.9 (Berkeley) %G%"; +static char sccsid[] = "@(#)macro.c 8.10 (Berkeley) %G%"; #endif /* not lint */ # include "sendmail.h" @@ -23,8 +23,7 @@ int NextMacroId = 0240; /* codes for long named macros */ ** Parameters: ** s -- the string to expand. ** buf -- the place to put the expansion. -** buflim -- the buffer limit, i.e., the address -** of the first byte after buf. +** bufsize -- the size of the buffer. ** e -- envelope in which to work. ** ** Returns: @@ -35,10 +34,10 @@ int NextMacroId = 0240; /* codes for long named macros */ */ void -expand(s, buf, buflim, e) +expand(s, buf, bufsize, e) register char *s; register char *buf; - char *buflim; + size_t bufsize; register ENVELOPE *e; { register char *xp; @@ -139,14 +138,14 @@ expand(s, buf, buflim, e) /* recurse as appropriate */ if (recurse) { - expand(xbuf, buf, buflim, e); + expand(xbuf, buf, bufsize, e); return; } /* copy results out */ - i = buflim - buf - 1; - if (i > xp - xbuf) - i = xp - xbuf; + i = xp - xbuf; + if (i >= bufsize) + i = bufsize - 1; bcopy(xbuf, buf, i); buf[i] = '\0'; } diff --git a/usr/src/usr.sbin/sendmail/src/main.c b/usr/src/usr.sbin/sendmail/src/main.c index 0fb5cf6547..b9c60ec189 100644 --- a/usr/src/usr.sbin/sendmail/src/main.c +++ b/usr/src/usr.sbin/sendmail/src/main.c @@ -13,7 +13,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)main.c 8.90 (Berkeley) %G%"; +static char sccsid[] = "@(#)main.c 8.91 (Berkeley) %G%"; #endif /* not lint */ #define _DEFINE @@ -757,7 +757,7 @@ main(argc, argv, envp) } /* our name for SMTP codes */ - expand("\201j", jbuf, &jbuf[sizeof jbuf - 1], CurEnv); + expand("\201j", jbuf, sizeof jbuf, CurEnv); MyHostName = jbuf; if (strchr(jbuf, '.') == NULL) message("WARNING: local host name (%s) is not qualified; fix $j in config file", diff --git a/usr/src/usr.sbin/sendmail/src/parseaddr.c b/usr/src/usr.sbin/sendmail/src/parseaddr.c index 44bcbdb9d9..f3fe77b65b 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.57 (Berkeley) %G%"; +static char sccsid[] = "@(#)parseaddr.c 8.58 (Berkeley) %G%"; #endif /* not lint */ #include "sendmail.h" @@ -435,7 +435,7 @@ prescan(addr, delim, pvpbuf, pvpbsize, delimptr) char obuf[50]; firsttime = FALSE; - expand("\201o", obuf, &obuf[sizeof obuf - sizeof DELIMCHARS], CurEnv); + expand("\201o", obuf, sizeof obuf - sizeof DELIMCHARS, CurEnv); strcat(obuf, DELIMCHARS); for (p = obuf; *p != '\0'; p++) { @@ -2121,9 +2121,9 @@ remotename(name, m, flags, pstat, e) /* need to make sure route-addrs have */ if (bitset(RF_CANONICAL, flags) && lbuf[0] == '@') - expand("<\201g>", buf, &buf[sizeof buf], e); + expand("<\201g>", buf, sizeof buf, e); else - expand(fancy, buf, &buf[sizeof buf], e); + expand(fancy, buf, sizeof buf, e); define('g', oldg, e); diff --git a/usr/src/usr.sbin/sendmail/src/queue.c b/usr/src/usr.sbin/sendmail/src/queue.c index a8e37026ca..0480576434 100644 --- a/usr/src/usr.sbin/sendmail/src/queue.c +++ b/usr/src/usr.sbin/sendmail/src/queue.c @@ -10,9 +10,9 @@ #ifndef lint #ifdef QUEUE -static char sccsid[] = "@(#)queue.c 8.67 (Berkeley) %G% (with queueing)"; +static char sccsid[] = "@(#)queue.c 8.68 (Berkeley) %G% (with queueing)"; #else -static char sccsid[] = "@(#)queue.c 8.67 (Berkeley) %G% (without queueing)"; +static char sccsid[] = "@(#)queue.c 8.68 (Berkeley) %G% (without queueing)"; #endif #endif /* not lint */ @@ -315,7 +315,7 @@ queueup(e, queueall, announce) /* expand macros; if null, don't output header at all */ if (bitset(H_DEFAULT, h->h_flags)) { - (void) expand(h->h_value, buf, &buf[sizeof buf], e); + (void) expand(h->h_value, buf, sizeof buf, e); if (buf[0] == '\0') continue; } diff --git a/usr/src/usr.sbin/sendmail/src/readcf.c b/usr/src/usr.sbin/sendmail/src/readcf.c index 4053640f00..413a85cf41 100644 --- a/usr/src/usr.sbin/sendmail/src/readcf.c +++ b/usr/src/usr.sbin/sendmail/src/readcf.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)readcf.c 8.73 (Berkeley) %G%"; +static char sccsid[] = "@(#)readcf.c 8.74 (Berkeley) %G%"; #endif /* not lint */ # include "sendmail.h" @@ -221,7 +221,7 @@ readcf(cfname) /* expand and save the LHS */ *p = '\0'; - expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); + expand(&bp[1], exbuf, sizeof exbuf, e); rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, sizeof pvpbuf, NULL); nfuzzy = 0; @@ -309,7 +309,7 @@ readcf(cfname) while (*p != '\0' && *p != '\t') p++; *p = '\0'; - expand(q, exbuf, &exbuf[sizeof exbuf], e); + expand(q, exbuf, sizeof exbuf, e); rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, sizeof pvpbuf, NULL); if (rwp->r_rhs != NULL) @@ -439,7 +439,7 @@ readcf(cfname) if (bp[0] == 'C') { mid = macid(&bp[1], &ep); - expand(ep, exbuf, &exbuf[sizeof exbuf], e); + expand(ep, exbuf, sizeof exbuf, e); p = exbuf; } else diff --git a/usr/src/usr.sbin/sendmail/src/savemail.c b/usr/src/usr.sbin/sendmail/src/savemail.c index 2721633a3f..5cfa6e8abc 100644 --- a/usr/src/usr.sbin/sendmail/src/savemail.c +++ b/usr/src/usr.sbin/sendmail/src/savemail.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)savemail.c 8.55 (Berkeley) %G%"; +static char sccsid[] = "@(#)savemail.c 8.56 (Berkeley) %G%"; #endif /* not lint */ # include "sendmail.h" @@ -183,7 +183,7 @@ savemail(e, sendbody) break; } - expand("\201n", buf, &buf[sizeof buf - 1], e); + expand("\201n", buf, sizeof buf, e); printf("\r\nMessage from %s...\r\n", buf); printf("Errors occurred while sending mail.\r\n"); if (e->e_xfp != NULL) @@ -324,7 +324,7 @@ savemail(e, sendbody) /* we have a home directory; open dead.letter */ define('z', p, e); - expand("\201z/dead.letter", buf, &buf[sizeof buf - 1], e); + expand("\201z/dead.letter", buf, sizeof buf, e); Verbose = TRUE; message("Saving message in %s", buf); Verbose = oldverb; @@ -528,7 +528,7 @@ returntosender(msg, returnq, sendbody, e) addheader("Subject", msg, ee); /* fake up an address header for the from person */ - expand("\201n", buf, &buf[sizeof buf - 1], e); + expand("\201n", buf, sizeof buf, e); if (parseaddr(buf, &ee->e_from, RF_COPYALL|RF_SENDERADDR, '\0', NULL, e) == NULL) { syserr("553 Can't parse myself!"); @@ -637,7 +637,7 @@ errbody(mci, e, separator) sprintf(buf, "The original message was received at %s", arpadate(ctime(&e->e_parent->e_ctime))); putline(buf, mci); - expand("from \201_", buf, &buf[sizeof buf - 1], e->e_parent); + expand("from \201_", buf, sizeof buf, e->e_parent); putline(buf, mci); putline("", mci); @@ -654,7 +654,7 @@ errbody(mci, e, separator) { while (fgets(buf, sizeof buf, xfile) != NULL) { - expand(buf, buf, &buf[sizeof buf - 1], e); + expand(buf, buf, sizeof buf, e); putline(buf, mci); } (void) fclose(xfile); @@ -663,7 +663,7 @@ errbody(mci, e, separator) } else { - expand(ErrMsgFile, buf, &buf[sizeof buf - 1], e); + expand(ErrMsgFile, buf, sizeof buf, e); putline(buf, mci); putline("", mci); } diff --git a/usr/src/usr.sbin/sendmail/src/sendmail.h b/usr/src/usr.sbin/sendmail/src/sendmail.h index 3adeaadc9d..7201b3f08b 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.102 (Berkeley) %G% + * @(#)sendmail.h 8.103 (Berkeley) %G% */ /* @@ -15,7 +15,7 @@ # ifdef _DEFINE # define EXTERN # ifndef lint -static char SmailSccsId[] = "@(#)sendmail.h 8.102 %G%"; +static char SmailSccsId[] = "@(#)sendmail.h 8.103 %G%"; # endif # else /* _DEFINE */ # define EXTERN extern @@ -1054,7 +1054,7 @@ extern char *queuename __P((ENVELOPE *, int)); extern time_t curtime __P(()); extern bool transienterror __P((int)); extern const char *errstring __P((int)); -extern void expand __P((char *, char *, char *, ENVELOPE *)); +extern void expand __P((char *, char *, size_t, ENVELOPE *)); extern void define __P((int, char *, ENVELOPE *)); extern char *macvalue __P((int, ENVELOPE *)); extern char *macname __P((int)); diff --git a/usr/src/usr.sbin/sendmail/src/srvrsmtp.c b/usr/src/usr.sbin/sendmail/src/srvrsmtp.c index bf7e409a5b..8a0d0bdb01 100644 --- a/usr/src/usr.sbin/sendmail/src/srvrsmtp.c +++ b/usr/src/usr.sbin/sendmail/src/srvrsmtp.c @@ -10,9 +10,9 @@ #ifndef lint #ifdef SMTP -static char sccsid[] = "@(#)srvrsmtp.c 8.55 (Berkeley) %G% (with SMTP)"; +static char sccsid[] = "@(#)srvrsmtp.c 8.56 (Berkeley) %G% (with SMTP)"; #else -static char sccsid[] = "@(#)srvrsmtp.c 8.55 (Berkeley) %G% (without SMTP)"; +static char sccsid[] = "@(#)srvrsmtp.c 8.56 (Berkeley) %G% (without SMTP)"; #endif #endif /* not lint */ @@ -124,7 +124,7 @@ smtp(e) CurSmtpClient = CurHostName; setproctitle("server %s startup", CurSmtpClient); - expand("\201e", inp, &inp[sizeof inp], e); + expand("\201e", inp, sizeof inp, e); if (BrokenSmtpPeers) { p = strchr(inp, '\n'); diff --git a/usr/src/usr.sbin/sendmail/src/usersmtp.c b/usr/src/usr.sbin/sendmail/src/usersmtp.c index 51a354bffb..3594529a8a 100644 --- a/usr/src/usr.sbin/sendmail/src/usersmtp.c +++ b/usr/src/usr.sbin/sendmail/src/usersmtp.c @@ -10,9 +10,9 @@ #ifndef lint #ifdef SMTP -static char sccsid[] = "@(#)usersmtp.c 8.37 (Berkeley) %G% (with SMTP)"; +static char sccsid[] = "@(#)usersmtp.c 8.38 (Berkeley) %G% (with SMTP)"; #else -static char sccsid[] = "@(#)usersmtp.c 8.37 (Berkeley) %G% (without SMTP)"; +static char sccsid[] = "@(#)usersmtp.c 8.38 (Berkeley) %G% (without SMTP)"; #endif #endif /* not lint */ @@ -387,7 +387,7 @@ smtpmailfrom(m, mci, e) !bitnset(M_NO_NULL_FROM, m->m_flags)) (void) strcpy(buf, ""); else - expand("\201g", buf, &buf[sizeof buf], e); + expand("\201g", buf, sizeof buf, e); if (buf[0] == '<') { /* strip off (put back on below) */