[comp.mail.sendmail] Long hostname bug in sendmail

hubert@cac.washington.edu (Steve Hubert) (10/18/90)

SHORT DESCRIPTION:
There is a character array jbuf[30] in main.c.  Jbuf is used to hold
the hostname so long names cause problems.

FIX:
Change the size of the array to MAXHOSTNAMELEN+1.

	bool readconfig = TRUE;
	bool queuemode = FALSE;		/* process queue requests */
	bool nothaw;
	static bool reenter = FALSE;
#ifdef JBUFFIX
	char jbuf[MAXHOSTNAMELEN + 1];	/* holds MyHostName */
#else /* JBUFFIX */
	char jbuf[30];			/* holds MyHostName */
#endif /* JBUFFIX */
	extern bool safefile();
	extern time_t convtime();
	extern putheader(), putbody();
	extern ENVELOPE *newenvelope();
	extern intsig();

LONGER DESCRIPTION:
There are two cases, either you set your hostname to its fully-qualified
name so that gethostname() returns the long name or you set your hostname
to its unqualified short name.
  Case 1:  myhostname() is called from main() and that calls gethostname()
	   with a pointer to jbuf[].  This will truncate your hostname
	   if it is over 30 characters and fail to null terminate it if
	   it is over 29 characters.  gethostbyname() is called with
	   this incorrect argument and it will fail.  Back in main() $w
	   is incorrectly defined to be this truncated name.  Later in main()
	   there is an expand('\001j', jbuf).  Expand has what appears to
	   be an off by one error in that it wastes one character in the
	   array it is passed.  (This is where the +1 comes from in
	   the FIX.)  Therefore, it uses only 29 characters of
	   jbuf[] and the last is a null so only 28 characters of a hostname.
	   The hostname truncated to 28 chars is stored as MyHostName and
	   that gets used in the HELO command by usersmtp().  Some mailers
	   object to a truncated hostname in the HELO command.  Some protest
	   even more (close the connection) if the truncated name ends
	   in a "." and so is technically a syntax error.  In particular,
	   many 31 character names will cause this syntax error since the
	   "edu" or "com" is sliced off the end.
  Case 2:  If your hostname is not FQ then you get past the first hurdle
	   but you eventually run into similar problems.


Steve Hubert
Networks and Distributed Computing, Univ. of Wash., Seattle
hubert@cac.washington.edu