be more precise on MAXNAME checking
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 15 Mar 1995 00:19:14 +0000 (16:19 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 15 Mar 1995 00:19:14 +0000 (16:19 -0800)
SCCS-vsn: usr.sbin/sendmail/src/usersmtp.c 8.37
SCCS-vsn: usr.sbin/sendmail/src/headers.c 8.49
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 8.72
SCCS-vsn: usr.sbin/sendmail/src/macro.c 8.9
SCCS-vsn: usr.sbin/sendmail/src/parseaddr.c 8.57
SCCS-vsn: usr.sbin/sendmail/src/savemail.c 8.55
SCCS-vsn: usr.sbin/sendmail/src/daemon.c 8.73
SCCS-vsn: usr.sbin/sendmail/src/deliver.c 8.129
SCCS-vsn: usr.sbin/sendmail/src/queue.c 8.67
SCCS-vsn: usr.sbin/sendmail/src/alias.c 8.38
SCCS-vsn: usr.sbin/sendmail/src/map.c 8.50

usr/src/usr.sbin/sendmail/src/alias.c
usr/src/usr.sbin/sendmail/src/daemon.c
usr/src/usr.sbin/sendmail/src/deliver.c
usr/src/usr.sbin/sendmail/src/headers.c
usr/src/usr.sbin/sendmail/src/macro.c
usr/src/usr.sbin/sendmail/src/map.c
usr/src/usr.sbin/sendmail/src/parseaddr.c
usr/src/usr.sbin/sendmail/src/queue.c
usr/src/usr.sbin/sendmail/src/recipient.c
usr/src/usr.sbin/sendmail/src/savemail.c
usr/src/usr.sbin/sendmail/src/usersmtp.c

index ea6c54e..7dc0e96 100644 (file)
@@ -10,7 +10,7 @@
 # include <pwd.h>
 
 #ifndef lint
 # include <pwd.h>
 
 #ifndef lint
-static char sccsid[] = "@(#)alias.c    8.37 (Berkeley) %G%";
+static char sccsid[] = "@(#)alias.c    8.38 (Berkeley) %G%";
 #endif /* not lint */
 
 
 #endif /* not lint */
 
 
@@ -309,7 +309,7 @@ aliaswait(map, ext, isopen)
        bool attimeout = FALSE;
        time_t mtime;
        struct stat stb;
        bool attimeout = FALSE;
        time_t mtime;
        struct stat stb;
-       char buf[MAXNAME];
+       char buf[MAXNAME + 1];
 
        if (tTd(27, 3))
                printf("aliaswait(%s:%s)\n",
 
        if (tTd(27, 3))
                printf("aliaswait(%s:%s)\n",
index 572ca7f..e90a7f4 100644 (file)
@@ -12,9 +12,9 @@
 
 #ifndef lint
 #ifdef DAEMON
 
 #ifndef lint
 #ifdef DAEMON
-static char sccsid[] = "@(#)daemon.c   8.72 (Berkeley) %G% (with daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.73 (Berkeley) %G% (with daemon mode)";
 #else
 #else
-static char sccsid[] = "@(#)daemon.c   8.72 (Berkeley) %G% (without daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.73 (Berkeley) %G% (without daemon mode)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -769,7 +769,7 @@ host_map_lookup(map, name, av, statp)
        struct in_addr in_addr;
        char *cp;
        register STAB *s;
        struct in_addr in_addr;
        char *cp;
        register STAB *s;
-       char hbuf[MAXNAME];
+       char hbuf[MAXNAME + 1];
        extern struct hostent *gethostbyaddr();
 #if NAMED_BIND
        extern int h_errno;
        extern struct hostent *gethostbyaddr();
 #if NAMED_BIND
        extern int h_errno;
@@ -814,7 +814,13 @@ host_map_lookup(map, name, av, statp)
                if (tTd(9, 1))
                        printf("host_map_lookup(%s) => ", name);
                s->s_namecanon.nc_flags |= NCF_VALID;           /* will be soon */
                if (tTd(9, 1))
                        printf("host_map_lookup(%s) => ", name);
                s->s_namecanon.nc_flags |= NCF_VALID;           /* will be soon */
-               (void) strcpy(hbuf, name);
+               if (strlen(name) < sizeof hbuf)
+                       (void) strcpy(hbuf, name);
+               else
+               {
+                       bcopy(name, hbuf, sizeof hbuf - 1);
+                       hbuf[sizeof hbuf - 1] = '\0';
+               }
                if (getcanonname(hbuf, sizeof hbuf - 1, TRUE))
                {
                        if (tTd(9, 1))
                if (getcanonname(hbuf, sizeof hbuf - 1, TRUE))
                {
                        if (tTd(9, 1))
index 6ecf49c..aaa8704 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)deliver.c  8.128 (Berkeley) %G%";
+static char sccsid[] = "@(#)deliver.c  8.129 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -636,8 +636,8 @@ deliver(e, firstto)
        int rpvect[2];
        char *pv[MAXPV+1];
        char tobuf[TOBUFSIZE];          /* text line of to people */
        int rpvect[2];
        char *pv[MAXPV+1];
        char tobuf[TOBUFSIZE];          /* text line of to people */
-       char buf[MAXNAME];
-       char rpathbuf[MAXNAME];         /* translated return path */
+       char buf[MAXNAME + 1];
+       char rpathbuf[MAXNAME + 1];     /* translated return path */
        extern int checkcompat();
 
        errno = 0;
        extern int checkcompat();
 
        errno = 0;
@@ -752,7 +752,7 @@ deliver(e, firstto)
                        break;
 
                /* this entry is safe -- go ahead and process it */
                        break;
 
                /* this entry is safe -- go ahead and process it */
-               expand(*mvp, buf, &buf[sizeof buf - 1], e);
+               expand(*mvp, buf, &buf[sizeof buf], e);
                *pvp++ = newstr(buf);
                if (pvp >= &pv[MAXPV - 3])
                {
                *pvp++ = newstr(buf);
                if (pvp >= &pv[MAXPV - 3])
                {
@@ -938,7 +938,7 @@ deliver(e, firstto)
 
                if (!clever)
                {
 
                if (!clever)
                {
-                       expand(*mvp, buf, &buf[sizeof buf - 1], e);
+                       expand(*mvp, buf, &buf[sizeof buf], e);
                        *pvp++ = newstr(buf);
                        if (pvp >= &pv[MAXPV - 2])
                        {
                        *pvp++ = newstr(buf);
                        if (pvp >= &pv[MAXPV - 2])
                        {
@@ -964,7 +964,7 @@ deliver(e, firstto)
 
        while (!clever && *++mvp != NULL)
        {
 
        while (!clever && *++mvp != NULL)
        {
-               expand(*mvp, buf, &buf[sizeof buf - 1], e);
+               expand(*mvp, buf, &buf[sizeof buf], e);
                *pvp++ = newstr(buf);
                if (pvp >= &pv[MAXPV])
                        syserr("554 deliver: pv overflow after $u for %s", pv[0]);
                *pvp++ = newstr(buf);
                if (pvp >= &pv[MAXPV])
                        syserr("554 deliver: pv overflow after $u for %s", pv[0]);
@@ -1080,7 +1080,7 @@ tryhost:
                while (*curhost != '\0')
                {
                        register char *p;
                while (*curhost != '\0')
                {
                        register char *p;
-                       static char hostbuf[MAXNAME];
+                       static char hostbuf[MAXNAME + 1];
 
                        /* pull the next host from the signature */
                        p = strchr(curhost, ':');
 
                        /* pull the next host from the signature */
                        p = strchr(curhost, ':');
@@ -1293,14 +1293,14 @@ tryhost:
                        if (m->m_execdir != NULL)
                        {
                                char *p, *q;
                        if (m->m_execdir != NULL)
                        {
                                char *p, *q;
-                               char buf[MAXLINE];
+                               char buf[MAXLINE + 1];
 
                                for (p = m->m_execdir; p != NULL; p = q)
                                {
                                        q = strchr(p, ':');
                                        if (q != NULL)
                                                *q = '\0';
 
                                for (p = m->m_execdir; p != NULL; p = q)
                                {
                                        q = strchr(p, ':');
                                        if (q != NULL)
                                                *q = '\0';
-                                       expand(p, buf, &buf[sizeof buf] - 1, e);
+                                       expand(p, buf, &buf[sizeof buf], e);
                                        if (q != NULL)
                                                *q++ = ':';
                                        if (tTd(11, 20))
                                        if (q != NULL)
                                                *q++ = ':';
                                        if (tTd(11, 20))
index e87bb92..ab66115 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)headers.c  8.48 (Berkeley) %G%";
+static char sccsid[] = "@(#)headers.c  8.49 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <errno.h>
 #endif /* not lint */
 
 # include <errno.h>
@@ -44,7 +44,7 @@ chompheader(line, def, e)
        struct hdrinfo *hi;
        bool cond = FALSE;
        BITMAP mopts;
        struct hdrinfo *hi;
        bool cond = FALSE;
        BITMAP mopts;
-       char buf[MAXNAME];
+       char buf[MAXNAME + 1];
        extern ADDRESS *sendto();
 
        if (tTd(31, 6))
        extern ADDRESS *sendto();
 
        if (tTd(31, 6))
@@ -540,9 +540,9 @@ logsender(e, msgid)
        register char *sbp;
        register char *p;
        int l;
        register char *sbp;
        register char *p;
        int l;
-       char hbuf[MAXNAME];
-       char sbuf[MAXLINE];
-       char mbuf[MAXNAME];
+       char hbuf[MAXNAME + 1];
+       char sbuf[MAXLINE + 1];
+       char mbuf[MAXNAME + 1];
 
        /* don't allow newlines in the message-id */
        if (msgid != NULL)
 
        /* don't allow newlines in the message-id */
        if (msgid != NULL)
@@ -701,7 +701,7 @@ crackaddr(addr)
        bool gotangle = FALSE;
        register char *bp;
        char *buflim;
        bool gotangle = FALSE;
        register char *bp;
        char *buflim;
-       static char buf[MAXNAME];
+       static char buf[MAXNAME + 1];
 
        if (tTd(33, 1))
                printf("crackaddr(%s)\n", addr);
 
        if (tTd(33, 1))
                printf("crackaddr(%s)\n", addr);
index cf568c3..6a3adc4 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)macro.c    8.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)macro.c    8.9 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -24,7 +24,7 @@ int   NextMacroId = 0240;     /* codes for long named macros */
 **             s -- the string to expand.
 **             buf -- the place to put the expansion.
 **             buflim -- the buffer limit, i.e., the address
 **             s -- the string to expand.
 **             buf -- the place to put the expansion.
 **             buflim -- the buffer limit, i.e., the address
-**                     of the last usable position in buf.
+**                     of the first byte after buf.
 **             e -- envelope in which to work.
 **
 **     Returns:
 **             e -- envelope in which to work.
 **
 **     Returns:
index af1df50..ed4ef26 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)map.c      8.49 (Berkeley) %G%";
+static char sccsid[] = "@(#)map.c      8.50 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -701,7 +701,7 @@ bt_map_open(map, mode)
        int omode;
        int fd;
        struct stat st;
        int omode;
        int fd;
        struct stat st;
-       char buf[MAXNAME];
+       char buf[MAXNAME + 1];
 
        if (tTd(38, 2))
                printf("bt_map_open(%s, %s, %d)\n",
 
        if (tTd(38, 2))
                printf("bt_map_open(%s, %s, %d)\n",
@@ -788,7 +788,7 @@ hash_map_open(map, mode)
        int omode;
        int fd;
        struct stat st;
        int omode;
        int fd;
        struct stat st;
-       char buf[MAXNAME];
+       char buf[MAXNAME + 1];
 
        if (tTd(38, 2))
                printf("hash_map_open(%s, %s, %d)\n",
 
        if (tTd(38, 2))
                printf("hash_map_open(%s, %s, %d)\n",
@@ -1433,7 +1433,7 @@ nisplus_map_lookup(map, name, av, statp)
 char *
 nisplus_default_domain()
 {
 char *
 nisplus_default_domain()
 {
-       static char default_domain[MAXNAME] = "";
+       static char default_domain[MAXNAME + 1] = "";
        char *p;
 
        if (default_domain[0] != '\0')
        char *p;
 
        if (default_domain[0] != '\0')
@@ -1681,7 +1681,7 @@ text_map_lookup(map, name, av, statp)
        char search_key[MAXNAME + 1];
        char linebuf[MAXLINE];
        FILE *f;
        char search_key[MAXNAME + 1];
        char linebuf[MAXLINE];
        FILE *f;
-       char buf[MAXNAME+1];
+       char buf[MAXNAME + 1];
        char delim;
        int key_idx;
        bool found_it;
        char delim;
        int key_idx;
        bool found_it;
index 93411e4..44bcbdb 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)parseaddr.c        8.56 (Berkeley) %G%";
+static char sccsid[] = "@(#)parseaddr.c        8.57 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -1581,7 +1581,7 @@ buildaddr(tv, a, flags, e)
        int spaceleft;
        static MAILER errormailer;
        static char *errorargv[] = { "ERROR", NULL };
        int spaceleft;
        static MAILER errormailer;
        static char *errorargv[] = { "ERROR", NULL };
-       static char buf[MAXNAME];
+       static char buf[MAXNAME + 1];
 
        if (tTd(24, 5))
        {
 
        if (tTd(24, 5))
        {
@@ -2032,8 +2032,8 @@ remotename(name, m, flags, pstat, e)
        char *fancy;
        char *oldg = macvalue('g', e);
        int rwset;
        char *fancy;
        char *oldg = macvalue('g', e);
        int rwset;
-       static char buf[MAXNAME];
-       char lbuf[MAXNAME];
+       static char buf[MAXNAME + 1];
+       char lbuf[MAXNAME + 1];
        char pvpbuf[PSBUFSIZE];
 
        if (tTd(12, 1))
        char pvpbuf[PSBUFSIZE];
 
        if (tTd(12, 1))
@@ -2121,9 +2121,9 @@ remotename(name, m, flags, pstat, e)
 
        /* need to make sure route-addrs have <angle brackets> */
        if (bitset(RF_CANONICAL, flags) && lbuf[0] == '@')
 
        /* need to make sure route-addrs have <angle brackets> */
        if (bitset(RF_CANONICAL, flags) && lbuf[0] == '@')
-               expand("<\201g>", buf, &buf[sizeof buf - 1], e);
+               expand("<\201g>", buf, &buf[sizeof buf], e);
        else
        else
-               expand(fancy, buf, &buf[sizeof buf - 1], e);
+               expand(fancy, buf, &buf[sizeof buf], e);
 
        define('g', oldg, e);
 
 
        define('g', oldg, e);
 
index 4180f72..a8e3702 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef QUEUE
 
 #ifndef lint
 #ifdef QUEUE
-static char sccsid[] = "@(#)queue.c    8.66 (Berkeley) %G% (with queueing)";
+static char sccsid[] = "@(#)queue.c    8.67 (Berkeley) %G% (with queueing)";
 #else
 #else
-static char sccsid[] = "@(#)queue.c    8.66 (Berkeley) %G% (without queueing)";
+static char sccsid[] = "@(#)queue.c    8.67 (Berkeley) %G% (without queueing)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -686,7 +686,7 @@ orderq(doall)
        {
                FILE *cf;
                register char *p;
        {
                FILE *cf;
                register char *p;
-               char lbuf[MAXNAME];
+               char lbuf[MAXNAME + 1];
                extern bool strcontainedin();
 
                /* is this an interesting entry? */
                extern bool strcontainedin();
 
                /* is this an interesting entry? */
@@ -726,8 +726,8 @@ orderq(doall)
                                syslog(LOG_CRIT, "orderq: bogus qf name %s",
                                        d->d_name);
 #endif
                                syslog(LOG_CRIT, "orderq: bogus qf name %s",
                                        d->d_name);
 #endif
-                       if (strlen(d->d_name) >= MAXNAME)
-                               d->d_name[MAXNAME - 1] = '\0';
+                       if (strlen(d->d_name) > MAXNAME)
+                               d->d_name[MAXNAME] = '\0';
                        strcpy(lbuf, d->d_name);
                        lbuf[0] = 'Q';
                        (void) rename(d->d_name, lbuf);
                        strcpy(lbuf, d->d_name);
                        lbuf[0] = 'Q';
                        (void) rename(d->d_name, lbuf);
@@ -1499,7 +1499,7 @@ printqueue()
                int flags = 0;
                int qfver;
                char message[MAXLINE];
                int flags = 0;
                int qfver;
                char message[MAXLINE];
-               char bodytype[MAXNAME];
+               char bodytype[MAXNAME + 1];
 
                printf("%8s", w->w_name + 2);
                f = fopen(w->w_name, "r");
 
                printf("%8s", w->w_name + 2);
                f = fopen(w->w_name, "r");
@@ -1646,7 +1646,7 @@ queuename(e, type)
        static char c2;
        time_t now;
        struct tm *tm;
        static char c2;
        time_t now;
        struct tm *tm;
-       static char buf[MAXNAME];
+       static char buf[MAXNAME + 1];
 
        if (e->e_id == NULL)
        {
 
        if (e->e_id == NULL)
        {
index 110dede..03556bf 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)recipient.c        8.71 (Berkeley) %G%";
+static char sccsid[] = "@(#)recipient.c        8.72 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -224,7 +224,7 @@ recipient(a, sendq, aliaslevel, e)
        int findusercount = 0;
        int i;
        char *buf;
        int findusercount = 0;
        int i;
        char *buf;
-       char buf0[MAXNAME];             /* unquoted image of the user name */
+       char buf0[MAXNAME + 1];         /* unquoted image of the user name */
        extern int safefile();
 
        e->e_to = a->q_paddr;
        extern int safefile();
 
        e->e_to = a->q_paddr;
@@ -259,7 +259,7 @@ recipient(a, sendq, aliaslevel, e)
 
        /* get unquoted user for file, program or user.name check */
        i = strlen(a->q_user);
 
        /* get unquoted user for file, program or user.name check */
        i = strlen(a->q_user);
-       if (i >= sizeof buf)
+       if (i >= sizeof buf0)
                buf = xalloc(i + 1);
        else
                buf = buf0;
                buf = xalloc(i + 1);
        else
                buf = buf0;
@@ -486,7 +486,7 @@ recipient(a, sendq, aliaslevel, e)
                }
                else
                {
                }
                else
                {
-                       char nbuf[MAXNAME];
+                       char nbuf[MAXNAME + 1];
 
                        if (fuzzy)
                        {
 
                        if (fuzzy)
                        {
index 26d569f..2721633 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)savemail.c 8.54 (Berkeley) %G%";
+static char sccsid[] = "@(#)savemail.c 8.55 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -434,7 +434,7 @@ returntosender(msg, returnq, sendbody, e)
        bool sendbody;
        register ENVELOPE *e;
 {
        bool sendbody;
        register ENVELOPE *e;
 {
-       char buf[MAXNAME];
+       char buf[MAXNAME + 1];
        extern putheader(), errbody();
        register ENVELOPE *ee;
        ENVELOPE *oldcur = CurEnv;
        extern putheader(), errbody();
        register ENVELOPE *ee;
        ENVELOPE *oldcur = CurEnv;
index e572c0b..51a354b 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)usersmtp.c 8.36 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)usersmtp.c 8.37 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)usersmtp.c 8.36 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)usersmtp.c 8.37 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -313,7 +313,7 @@ smtpmailfrom(m, mci, e)
        int r;
        char *bufp;
        char *bodytype;
        int r;
        char *bufp;
        char *bodytype;
-       char buf[MAXNAME];
+       char buf[MAXNAME + 1];
        char optbuf[MAXLINE];
 
        if (tTd(18, 2))
        char optbuf[MAXLINE];
 
        if (tTd(18, 2))
@@ -387,7 +387,7 @@ smtpmailfrom(m, mci, e)
            !bitnset(M_NO_NULL_FROM, m->m_flags))
                (void) strcpy(buf, "");
        else
            !bitnset(M_NO_NULL_FROM, m->m_flags))
                (void) strcpy(buf, "");
        else
-               expand("\201g", buf, &buf[sizeof buf - 1], e);
+               expand("\201g", buf, &buf[sizeof buf], e);
        if (buf[0] == '<')
        {
                /* strip off <angle brackets> (put back on below) */
        if (buf[0] == '<')
        {
                /* strip off <angle brackets> (put back on below) */