fix bogus implementation of name overflow limiting
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Fri, 3 Dec 1993 02:17:57 +0000 (18:17 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Fri, 3 Dec 1993 02:17:57 +0000 (18:17 -0800)
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

usr/src/usr.sbin/sendmail/src/conf.h
usr/src/usr.sbin/sendmail/src/deliver.c
usr/src/usr.sbin/sendmail/src/envelope.c
usr/src/usr.sbin/sendmail/src/parseaddr.c
usr/src/usr.sbin/sendmail/src/sendmail.h
usr/src/usr.sbin/sendmail/src/util.c

index 93ebaf4..a58df6f 100644 (file)
@@ -5,7 +5,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %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 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 */
 
 # 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
 
 # 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 */
 /* fork routine -- set above using #ifdef _osname_ or in Makefile */
 # ifndef FORK
 # define FORK          vfork           /* function to call to fork mailer */
index 09c0a7a..d25a190 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #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"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -1779,12 +1779,7 @@ logdelivery(m, mci, stat, ctladdr, e)
        if (ctladdr != NULL)
        {
                strcpy(bp, ", ctladdr=");
        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))
                {
                bp += strlen(bp);
                if (bitset(QGOODUID, ctladdr->q_flags))
                {
index b7f7c78..0f4af92 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #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"
 #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",
                        }
                        syslog(LOG_NOTICE,
                                "setsender: %s: invalid or unparseable, received from %s",
-                               from, p);
+                               shortenstring(from, 83), p);
                }
 # endif /* LOG */
                if (from != NULL)
                }
 # endif /* LOG */
                if (from != NULL)
index c4624c7..3a7ffb0 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #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"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -103,14 +103,6 @@ parseaddr(addr, a, flags, delim, delimptr, e)
        if (delimptr == NULL)
                delimptr = &delimptrbuf;
 
        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)
        {
        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");
                                if (q >= &pvpbuf[PSBUFSIZE - 5])
                                {
                                        usrerr("553 Address too long");
+       returnnull:
                                        if (delimptr != NULL)
                                                *delimptr = p;
                                        CurEnv->e_to = saveto;
                                        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 (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;
                }
                        }
                        *avp++ = tok;
                }
index 9ab79a3..6354cce 100644 (file)
@@ -5,7 +5,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %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
 # 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
 # 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 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__
 
 /* ellipsis is a different case though */
 #ifdef __STDC__
index 5981107..e06b0fa 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #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"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -1347,3 +1347,52 @@ printit:
        else
                printf("%s\n", buf);
 }
        else
                printf("%s\n", buf);
 }
+\f/*
+**  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;
+}