[net.bugs.usg] Many problems with "mailx"

guy@sun.uucp (Guy Harris) (08/10/85)

1) "mailx" only supports a message length equal to the largest unsigned
"int".  "Mail" was modified after "mailx" split off so that it stored the
message length in a "long".

2) "mailx" doesn't handle RFC822 addresses properly.  The routine "skin"
does not understand RFC822 addresses (in fact, the comment at the front
explicitly says it's for RFC733 addresses).  Furthermore, "skin" isn't used
to scan things like the "From:" line when a message is being replied to,
even though it should be.

3) If an address begins with a "!", the routine "nameof" returns a pointer
to the "!" rather than the character following it.

4) There are a couple of places where pointers are not checked to see that
they are not NULL before they are dereferenced.

5) "From " lines containing quotes are not handled properly.

6) The user's ".mailrc" is normally not sourced until the mailbox file is
read in, so that if it contains a "cd" it won't invalidate the path for the
mailbox file.  However, if the mailbox file is specified as a folder (i.e.,
"+foldername"), the ".mailrc" must be sourced first so that the user's
"folder" directory can be used to find the mailbox file.

7) A couple of routines in "mailx" use pointer variables which have never
been set.

One of the routines (rename) is never used.  The code that uses
it has #ifdef OPTIM around it but is also commented out.  "mailx"
is badly in need of "lint"ing.  There are a lot of unused
variables and functions, a lot of functions which are not properly
declared, a lot of routines whose return value is never used, etc..

8) In one place, "mailx" assumes that a "malloc" will always succeed, which
is a very bad assumption to make.

Here are the fixes.

aux.c:
*** aux.c.orig	Fri Aug  9 01:30:38 1985
--- aux.c	Fri Aug  9 14:04:24 1985
***************
*** 124,143
  }
  
  /*
-  * Compute the size in characters of the passed message
-  */
- 
- unsigned int
- msize(messp)
- 	struct message *messp;
- {
- 	register struct message *mp;
- 
- 	mp = messp;
- 	return(mp->m_size);
- }
- 
- /*
   * Count the number of arguments in the given string raw list.
   */
  

--- 124,129 -----
  }
  
  /*
   * Count the number of arguments in the given string raw list.
   */
  
***************
*** 527,533
  	cp2--;
  	while (cp2 > cp && *cp2 != '!')
  		cp2--;
! 	return(cp2);
  }
  
  /*

--- 513,521 -----
  	cp2--;
  	while (cp2 > cp && *cp2 != '!')
  		cp2--;
! 	if (*cp2 == '!')
! 		return(cp2 + 1);
! 	return(cp);
  }
  
  /*
***************
*** 531,537
  }
  
  /*
!  * Skin an arpa net address according to the RFC 733 interpretation
   * of "host-phrase."
   */
  char *

--- 519,525 -----
  }
  
  /*
!  * Skin an arpa net address according to the RFC 822 interpretation
   * of "host-phrase."
   */
  char *
***************
*** 542,547
  	register char *cp, *cp2;
  	int gotlt, lastsp;
  	char nbuf[BUFSIZ];
  
  	if (name == NOSTR)
  		return(NOSTR);

--- 530,536 -----
  	register char *cp, *cp2;
  	int gotlt, lastsp;
  	char nbuf[BUFSIZ];
+ 	int nesting;
  
  	if (name == NOSTR)
  		return(NOSTR);
***************
*** 545,551
  
  	if (name == NOSTR)
  		return(NOSTR);
! 	if (index(name, '(') == NOSTR && index(name, '<') == NOSTR)
  		return(name);
  	gotlt = 0;
  	lastsp = 0;

--- 534,541 -----
  
  	if (name == NOSTR)
  		return(NOSTR);
! 	if (index(name, '(') == NOSTR && index(name, '<') == NOSTR
! 	&& index(name, ' ') == NOSTR)
  		return(name);
  	gotlt = 0;
  	lastsp = 0;
***************
*** 549,555
  		return(name);
  	gotlt = 0;
  	lastsp = 0;
! 	for (cp = name, cp2 = nbuf, c = *cp++; *cp; c = *cp++) {
  		switch (c) {
  		case '(':
  			while (*cp != ')' && *cp != 0)

--- 539,546 -----
  		return(name);
  	gotlt = 0;
  	lastsp = 0;
! 	bufend = nbuf;
! 	for (cp = name, cp2 = bufend; c = *cp++; ) {
  		switch (c) {
  		case '(':
  			/*
***************
*** 552,558
  	for (cp = name, cp2 = nbuf, c = *cp++; *cp; c = *cp++) {
  		switch (c) {
  		case '(':
! 			while (*cp != ')' && *cp != 0)
  				cp++;
  			if (*cp)
  				cp++;

--- 543,554 -----
  	for (cp = name, cp2 = bufend; c = *cp++; ) {
  		switch (c) {
  		case '(':
! 			/*
! 			 * Start of a "comment".
! 			 * Ignore it.
! 			 */
! 			nesting = 1;
! 			while ((c = *cp) != 0) {
  				cp++;
  				switch (c) {
  				case '\\':
***************
*** 554,560
  		case '(':
  			while (*cp != ')' && *cp != 0)
  				cp++;
! 			if (*cp)
  				cp++;
  			break;
  

--- 550,583 -----
  			nesting = 1;
  			while ((c = *cp) != 0) {
  				cp++;
! 				switch (c) {
! 				case '\\':
! 					if (*cp == 0)
! 						goto outcm;
! 					cp++;
! 					break;
! 				case '(':
! 					nesting++;
! 					break;
! 
! 				case ')':
! 					--nesting;
! 					break;
! 				}
! 
! 				if (nesting <= 0)
! 					break;
! 			}
! 		outcm:
! 			lastsp = 0;
! 			break;
! 
! 		case '"':
! 			/*
! 			 * Start of a "quoted-string".
! 			 * Copy it in its entirety.
! 			 */
! 			while ((c = *cp) != 0) {
  				cp++;
  				switch (c) {
  				case '\\':
***************
*** 556,561
  				cp++;
  			if (*cp)
  				cp++;
  			break;
  
  		case ' ':

--- 579,597 -----
  			 */
  			while ((c = *cp) != 0) {
  				cp++;
+ 				switch (c) {
+ 				case '\\':
+ 					if ((c = *cp) == 0)
+ 						goto outqs;
+ 					cp++;
+ 					break;
+ 				case '"':
+ 					goto outqs;
+ 				}
+ 				*cp2++ = c;
+ 			}
+ 		outqs:
+ 			lastsp = 0;
  			break;
  
  		case ' ':
***************
*** 569,576
  			break;
  
  		case '>':
! 			if (gotlt)
! 				goto done;
  
  			/* Fall into . . . */
  

--- 605,621 -----
  			break;
  
  		case '>':
! 			if (gotlt) {
! 				gotlt = 0;
! 				while (*cp != ',' && *cp != 0)
! 					cp++;
! 				if (*cp == 0 )
! 					goto done;
! 				*cp2++ = ',';
! 				*cp2++ = ' ';
! 				bufend = cp2;
! 				break;
! 			}
  
  			/* Fall into . . . */
  

cmd2.c:
*** cmd2.c.orig	Fri Aug  9 01:30:40 1985
--- cmd2.c	Fri Aug  9 02:12:22 1985
***************
*** 195,201
  	char *disp;
  	FILE *obuf;
  	struct stat statb;
! 	int lc, cc, t;
  
  	printf("\"%s\" ", file);
  	flush();

--- 195,202 -----
  	char *disp;
  	FILE *obuf;
  	struct stat statb;
! 	int lc, t;
! 	long cc;
  
  	printf("\"%s\" ", file);
  	flush();
***************
*** 207,213
  		perror("");
  		return(1);
  	}
! 	cc = lc = 0;
  	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
  		mesg = *ip;
  		touch(mesg);

--- 208,215 -----
  		perror("");
  		return(1);
  	}
! 	cc = 0L;
! 	lc = 0;
  	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
  		mesg = *ip;
  		touch(mesg);
***************
*** 218,224
  			return(1);
  		}
  		lc += t;
! 		cc += msize(mp);
  		if (mark)
  			mp->m_flag |= MSAVED;
  	}

--- 220,226 -----
  			return(1);
  		}
  		lc += t;
! 		cc += mp->m_size;
  		if (mark)
  			mp->m_flag |= MSAVED;
  	}
***************
*** 226,232
  	if (ferror(obuf))
  		perror(file);
  	fclose(obuf);
! 	printf("%s %d/%d\n", disp, lc, cc);
  }
  
  /*

--- 228,234 -----
  	if (ferror(obuf))
  		perror(file);
  	fclose(obuf);
! 	printf("%s %d/%ld\n", disp, lc, cc);
  }
  
  /*
***************
*** 241,247
  	register struct message *mp;
  	register char *file, *disp;
  	char linebuf[BUFSIZ];
! 	int f, *msgvec, lc, cc, t;
  	FILE *obuf, *mesf;
  	struct stat statb;
  

--- 243,250 -----
  	register struct message *mp;
  	register char *file, *disp;
  	char linebuf[BUFSIZ];
! 	int f, *msgvec, lc, t;
! 	long cc;
  	FILE *obuf, *mesf;
  	struct stat statb;
  
***************
*** 272,278
  		perror("");
  		return(1);
  	}
! 	cc = lc = 0;
  	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
  		mesg = *ip;
  		touch(mesg);

--- 275,282 -----
  		perror("");
  		return(1);
  	}
! 	cc = 0L;
! 	lc = 0;
  	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
  		mesg = *ip;
  		touch(mesg);
***************
*** 283,289
  		while (t-- > 0) {
  			fgets(linebuf, BUFSIZ, mesf);
  			fputs(linebuf, obuf);
! 			cc += strlen(linebuf);
  		}
  		lc += mp->m_lines - 2;
  		mp->m_flag |= MSAVED;

--- 287,293 -----
  		while (t-- > 0) {
  			fgets(linebuf, BUFSIZ, mesf);
  			fputs(linebuf, obuf);
! 			cc += (long)strlen(linebuf);
  		}
  		lc += mp->m_lines - 2;
  		mp->m_flag |= MSAVED;
***************
*** 292,298
  	if (ferror(obuf))
  		perror(file);
  	fclose(obuf);
! 	printf("%s %d/%d\n", disp, lc, cc);
  	return(0);
  }
  

--- 296,302 -----
  	if (ferror(obuf))
  		perror(file);
  	fclose(obuf);
! 	printf("%s %d/%ld\n", disp, lc, cc);
  	return(0);
  }
  

cmd3.c:
*** cmd3.c.orig	Fri Aug  9 01:30:41 1985
--- cmd3.c	Fri Aug  9 02:14:30 1985
***************
*** 229,236
  
  	mp = &message[msgvec[0] - 1];
  	dot = mp;
! 	if ((rcv = hfield("from", mp))==NOSTR)
! 		rcv = nameof(mp, 1);
  	getrecf(rcv, recfile, useauthor);
  	replyto = skin(hfield("reply-to", mp));
  	strcpy(buf, "");

--- 229,236 -----
  
  	mp = &message[msgvec[0] - 1];
  	dot = mp;
! 	if ((rcv = skin(hfield("from", mp)))==NOSTR)
! 		rcv = skin(nameof(mp, 1));
  	getrecf(rcv, recfile, useauthor);
  	replyto = skin(hfield("reply-to", mp));
  	strcpy(buf, "");
***************
*** 237,243
  	if (replyto != NOSTR)
  		strcpy(buf, replyto);
  	else {
! 		cp = hfield("to", mp);
  		if (cp != NOSTR)
  			strcpy(buf, cp);
  	}

--- 237,243 -----
  	if (replyto != NOSTR)
  		strcpy(buf, replyto);
  	else {
! 		cp = skin(hfield("to", mp));
  		if (cp != NOSTR)
  			strcpy(buf, cp);
  	}
***************
*** 385,391
  	for (ip = msgvec; *ip != NULL; ip++) {
  		mesg = *ip;
  		mp = &message[mesg-1];
! 		printf("%d: %d\n", mesg, msize(mp));
  	}
  	return(0);
  }

--- 385,391 -----
  	for (ip = msgvec; *ip != NULL; ip++) {
  		mesg = *ip;
  		mp = &message[mesg-1];
! 		printf("%d: %ld\n", mesg, mp->m_size);
  	}
  	return(0);
  }
***************
*** 720,726
  	struct header head;
  	struct message *mp;
  	register int s, *ap;
! 	register char *cp, *subject;
  
  	for (s = 0, ap = msgvec; *ap != 0; ap++) {
  		mp = &message[*ap - 1];

--- 720,726 -----
  	struct header head;
  	struct message *mp;
  	register int s, *ap;
! 	register char *cp, *cp2, *subject;
  
  	for (s = 0, ap = msgvec; *ap != 0; ap++) {
  		mp = &message[*ap - 1];
***************
*** 725,731
  	for (s = 0, ap = msgvec; *ap != 0; ap++) {
  		mp = &message[*ap - 1];
  		dot = mp;
! 		s += strlen(nameof(mp, 2)) + 1;
  	}
  	if (s == 0)
  		return(0);

--- 725,734 -----
  	for (s = 0, ap = msgvec; *ap != 0; ap++) {
  		mp = &message[*ap - 1];
  		dot = mp;
! 		if ((cp = skin(hfield("from", mp))) != NOSTR)
! 			s += strlen(cp) + 1;
! 		else
! 			s += strlen(nameof(mp, 2)) + 1;
  	}
  	if (s == 0)
  		return(0);
***************
*** 733,739
  	head.h_to = cp;
  	for (ap = msgvec; *ap != 0; ap++) {
  		mp = &message[*ap - 1];
! 		cp = copy(nameof(mp, 2), cp);
  		*cp++ = ' ';
  	}
  	*--cp = 0;

--- 736,744 -----
  	head.h_to = cp;
  	for (ap = msgvec; *ap != 0; ap++) {
  		mp = &message[*ap - 1];
! 		if ((cp2 = skin(hfield("from", mp))) == NOSTR)
! 			cp2 = skin(nameof(mp, 2));
! 		cp = copy(cp2, cp);
  		*cp++ = ' ';
  	}
  	*--cp = 0;

cmd4.c:
*** cmd4.c.orig	Fri Aug  9 01:30:42 1985
--- cmd4.c	Fri Aug  9 02:16:06 1985
***************
*** 22,28
  	register int *ip, mesg;
  	register struct message *mp;
  	char *cp, *cmd;
! 	int f, *msgvec, lc, cc, t, nowait=0;
  	register int pid;
  	int page, s, pivec[2], (*sigint)();
  	char *Shell;

--- 22,29 -----
  	register int *ip, mesg;
  	register struct message *mp;
  	char *cp, *cmd;
! 	int f, *msgvec, lc, t, nowait=0;
! 	long cc;
  	register int pid;
  	int page, s, pivec[2], (*sigint)();
  	char *Shell;
***************
*** 88,94
  
  					/* send all messages to cmd */
  	page = (value("page")!=NOSTR);
! 	cc = lc = 0;
  	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
  		mesg = *ip;
  		touch(mesg);

--- 89,96 -----
  
  					/* send all messages to cmd */
  	page = (value("page")!=NOSTR);
! 	cc = 0L;
! 	lc = 0;
  	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
  		mesg = *ip;
  		touch(mesg);
***************
*** 98,104
  			return(1);
  		}
  		lc += t;
! 		cc += msize(mp);
  		if (page) putc('\f', pio);
  	}
  

--- 100,106 -----
  			return(1);
  		}
  		lc += t;
! 		cc += mp->m_size;
  		if (page) putc('\f', pio);
  	}
  
***************
*** 117,123
  		}
  	}
  
! 	printf("\"%s\" %d/%d\n", cmd, lc, cc);
  	return(0);
  
  err:

--- 119,125 -----
  		}
  	}
  
! 	printf("\"%s\" %d/%ld\n", cmd, lc, cc);
  	return(0);
  
  err:

collect.c:
*** collect.c.orig	Fri Aug  9 01:30:43 1985
--- collect.c	Fri Aug  9 02:21:11 1985
***************
*** 736,742
  		touch(*ip);
  		printf(" %d", *ip);
  		if (f == 'm') {
! 			if (transmit(&message[*ip-1], obuf) < 0) {
  				perror(tempMail);
  				return(-1);
  			}

--- 736,742 -----
  		touch(*ip);
  		printf(" %d", *ip);
  		if (f == 'm') {
! 			if (transmit(&message[*ip-1], obuf) < 0L) {
  				perror(tempMail);
  				return(-1);
  			}
***************
*** 757,762
   * on error.
   */
  
  transmit(mailp, obuf)
  	struct message *mailp;
  	FILE *obuf;

--- 757,763 -----
   * on error.
   */
  
+ long
  transmit(mailp, obuf)
  	struct message *mailp;
  	FILE *obuf;
***************
*** 762,769
  	FILE *obuf;
  {
  	register struct message *mp;
! 	register int c, ch;
! 	int n, bol;
  	FILE *ibuf;
  
  	mp = mailp;

--- 763,771 -----
  	FILE *obuf;
  {
  	register struct message *mp;
! 	register int ch;
! 	register long c, n;
! 	int bol;
  	FILE *ibuf;
  
  	mp = mailp;
***************
*** 768,774
  
  	mp = mailp;
  	ibuf = setinput(mp);
! 	c = msize(mp);
  	n = c;
  	bol = 1;
  	while (c-- > 0) {

--- 770,776 -----
  
  	mp = mailp;
  	ibuf = setinput(mp);
! 	c = mp->m_size;
  	n = c;
  	bol = 1;
  	while (c-- > 0L) {
***************
*** 771,777
  	c = msize(mp);
  	n = c;
  	bol = 1;
! 	while (c-- > 0) {
  		if (bol) {
  			bol = 0;
  			putc('\t', obuf);

--- 773,779 -----
  	c = mp->m_size;
  	n = c;
  	bol = 1;
! 	while (c-- > 0L) {
  		if (bol) {
  			bol = 0;
  			putc('\t', obuf);
***************
*** 778,784
  			n++;
  			if (ferror(obuf)) {
  				perror("/tmp");
! 				return(-1);
  			}
  		}
  		ch = getc(ibuf);

--- 780,786 -----
  			n++;
  			if (ferror(obuf)) {
  				perror("/tmp");
! 				return(-1L);
  			}
  		}
  		ch = getc(ibuf);
***************
*** 787,793
  		putc(ch, obuf);
  		if (ferror(obuf)) {
  			perror("/tmp");
! 			return(-1);
  		}
  	}
  	return(n);

--- 789,795 -----
  		putc(ch, obuf);
  		if (ferror(obuf)) {
  			perror("/tmp");
! 			return(-1L);
  		}
  	}
  	return(n);

edit.c:
*** edit.c.orig	Fri Aug  9 01:30:45 1985
--- edit.c	Fri Aug  9 02:23:41 1985
***************
*** 53,59
  {
  	register int c;
  	int *ip, pid, mesg, lines;
! 	unsigned int ms;
  	int (*sigint)(), (*sigquit)();
  	FILE *ibuf, *obuf;
  	struct message *mp;

--- 53,59 -----
  {
  	register int c;
  	int *ip, pid, mesg, lines;
! 	long ms;
  	int (*sigint)(), (*sigquit)();
  	FILE *ibuf, *obuf;
  	struct message *mp;
***************
*** 173,179
  		size = fsize(otf);
  		mp->m_block = blockof(size);
  		mp->m_offset = offsetof(size);
! 		ms = 0;
  		lines = 0;
  		while ((c = getc(ibuf)) != EOF) {
  			if (c == '\n')

--- 173,179 -----
  		size = fsize(otf);
  		mp->m_block = blockof(size);
  		mp->m_offset = offsetof(size);
! 		ms = 0L;
  		lines = 0;
  		while ((c = getc(ibuf)) != EOF) {
  			if (c == '\n')

fio.c:
*** fio.c.orig	Fri Aug  9 01:30:47 1985
--- fio.c	Fri Aug  9 02:27:59 1985
***************
*** 23,29
  {
  	register int c;
  	register char *cp, *cp2;
! 	register int count, s, l;
  	off_t offset;
  	char linebuf[LINESIZE];
  	char wbuf[LINESIZE];

--- 23,30 -----
  {
  	register int c;
  	register char *cp, *cp2;
! 	register int count, l;
! 	register long s;
  	off_t offset;
  	char linebuf[LINESIZE];
  	char wbuf[LINESIZE];
***************
*** 35,41
  		exit(1);
  	msgCount = 0;
  	offset = 0;
! 	s = 0;
  	l = 0;
  	maybe = 1;
  	flag = MUSED|MNEW;

--- 36,42 -----
  		exit(1);
  	msgCount = 0;
  	offset = 0;
! 	s = 0L;
  	l = 0;
  	maybe = 1;
  	flag = MUSED|MNEW;
***************
*** 89,95
  			this.m_offset = offsetof(offset);
  			this.m_size = s;
  			this.m_lines = l;
! 			s = 0;
  			l = 0;
  			if (append(&this, mestmp)) {
  				perror(tempSet);

--- 90,96 -----
  			this.m_offset = offsetof(offset);
  			this.m_size = s;
  			this.m_lines = l;
! 			s = 0L;
  			l = 0;
  			if (append(&this, mestmp)) {
  				perror(tempSet);
***************
*** 114,120
  			}
  		}
  		offset += count;
! 		s += count;
  		l++;
  		maybe = 0;
  		if (linebuf[0] == 0)

--- 115,121 -----
  			}
  		}
  		offset += count;
! 		s += (long)count;
  		l++;
  		maybe = 0;
  		if (linebuf[0] == 0)
***************
*** 255,261
  		m->m_lines = (m+1)->m_lines;
  		m->m_flag = (m+1)->m_flag;
  	}
! 	message[msgCount].m_size = 0;
  	message[msgCount].m_lines = 0;
  }
  

--- 256,262 -----
  		m->m_lines = (m+1)->m_lines;
  		m->m_flag = (m+1)->m_flag;
  	}
! 	message[msgCount].m_size = 0L;
  	message[msgCount].m_lines = 0;
  }

  

head.c:
*** head.c.orig	Fri Aug  9 01:30:48 1985
--- head.c	Fri Aug  9 02:30:48 1985
***************
*** 85,90
  
  	cp = nextword(cp, word);
  	dp = nextword(cp, word);
  	if (!equal(word, ""))
  		hl->l_from = copyin(word, &sp);
  	if (isname(dp, "tty", 3)) {

--- 85,92 -----
  
  	cp = nextword(cp, word);
  	dp = nextword(cp, word);
+ 	if (dp == NOSTR)
+ 		return;
  	if (!equal(word, ""))
  		hl->l_from = copyin(word, &sp);
  	if (isname(dp, "tty", 3)) {
***************
*** 271,277
  	}
  	cp2 = wbuf;
  	while (!any(*cp, " \t") && *cp != '\0')
! 		*cp2++ = *cp++;
  	*cp2 = '\0';
  	while (any(*cp, " \t"))
  		cp++;

--- 273,286 -----
  	}
  	cp2 = wbuf;
  	while (!any(*cp, " \t") && *cp != '\0')
! 		if (*cp == '"') {
! 			*cp2++ = *cp++;
! 			while (*cp != '\0' && *cp != '"')
! 				*cp2++ = *cp++;
! 			if (*cp == '"')
! 				*cp2++ = *cp++;
! 		} else
! 			*cp2++ = *cp++;
  	*cp2 = '\0';
  	while (any(*cp, " \t"))
  		cp++;
lex.c:
*** lex.c.orig	Fri Aug  9 01:30:50 1985
--- lex.c	Fri Aug  9 02:33:34 1985
***************
*** 478,483
  
  	if (msgvec != (int *) 0)
  		cfree(msgvec);
  	msgvec = (int *) calloc((unsigned) (sz + 1), sizeof *msgvec);
  }
  

--- 478,485 -----
  
  	if (msgvec != (int *) 0)
  		cfree(msgvec);
+ 	if (sz < 1)
+ 		sz = 1;	/* need at least one cell for terminating 0 */
  	msgvec = (int *) calloc((unsigned) (sz + 1), sizeof *msgvec);
  }
  

main.c:
*** main.c.orig	Fri Aug  9 01:30:54 1985
--- main.c	Fri Aug  9 02:36:36 1985
***************
*** 33,38
  	register char *ef;
  	register int i, argp;
  	int mustsend, uflag, hdrstop(), (*prevint)(), f;
  	FILE *ibuf, *ftat;
  	extern char _sobuf[];
  	struct termio tbuf;

--- 33,39 -----
  	register char *ef;
  	register int i, argp;
  	int mustsend, uflag, hdrstop(), (*prevint)(), f;
+ 	int loaded = 0;
  	FILE *ibuf, *ftat;
  	extern char _sobuf[];
  	struct termio tbuf;
***************
*** 287,293
  	 * the system mailbox, and open up the right stuff.
  	 *
  	 * Do this before sourcing the MAILRC, because there might be
! 	 * a 'chdir' there that breaks the -f option.
  	 */
  
  	if (ef != NOSTR) {

--- 288,296 -----
  	 * the system mailbox, and open up the right stuff.
  	 *
  	 * Do this before sourcing the MAILRC, because there might be
! 	 * a 'chdir' there that breaks the -f option.  But if the
! 	 * file specified with -f is a folder name, go ahead and
! 	 * source the MAILRC anyway so that "folder" will be defined.
  	 */
  
  	if (ef != NOSTR) {
***************
*** 294,299
  		char *ename;
  
  		edit++;
  		ename = expand(ef);
  		if (ename != ef) {
  			ef = (char *) calloc(1, strlen(ename) + 1);

--- 297,306 -----
  		char *ename;
  
  		edit++;
+ 		if (*ef == '+') {
+ 			load(Getf("MAILRC"));
+ 			loaded++;
+ 		}
  		ename = expand(ef);
  		if (ename != ef) {
  			ef = (char *) calloc(1, strlen(ename) + 1);
***************
*** 306,312
  	if (setfile(mailname, edit) < 0)
  		exit(1);
  
! 	load(Getf("MAILRC"));
  	if (msgCount > 0 && !noheader && value("header") != NOSTR) {
  		if (setjmp(hdrjmp) == 0) {
  			if ((prevint = sigset(SIGINT, SIG_IGN)) != SIG_IGN)

--- 313,320 -----
  	if (setfile(mailname, edit) < 0)
  		exit(1);
  
! 	if (!loaded)
! 		load(Getf("MAILRC"));
  	if (msgCount > 0 && !noheader && value("header") != NOSTR) {
  		if (setjmp(hdrjmp) == 0) {
  			if ((prevint = sigset(SIGINT, SIG_IGN)) != SIG_IGN)

optim.c:
*** optim.c.orig	Fri Aug  9 01:30:57 1985
--- optim.c	Fri Aug  9 14:49:26 1985
***************
*** 117,122
  	char buf[BUFSIZ], path[BUFSIZ];
  	register int c, host;
  
  	strcpy(path, "");
  	for (;;) {
  		if ((c = *cp++) == 0)

--- 117,123 -----
  	char buf[BUFSIZ], path[BUFSIZ];
  	register int c, host;
  
+ 	cp = str;
  	strcpy(path, "");
  	for (;;) {
  		if ((c = *cp++) == 0)
***************
*** 724,729
  {
  	register char *cp, *last;
  
  	last = NOSTR;
  	while (*cp) {
  		if (*cp == mach)

--- 725,731 -----
  {
  	register char *cp, *last;
  
+ 	cp = str;
  	last = NOSTR;
  	while (*cp) {
  		if (*cp == mach)

send.c:
*** send.c.orig	Fri Aug  9 01:31:00 1985
--- send.c	Fri Aug  9 12:29:10 1985
***************
*** 27,33
  {
  	register struct message *mp;
  	register int t;
! 	unsigned int c;
  	FILE *ibuf;
  	char line[LINESIZE], field[BUFSIZ];
  	int lc, ishead, infld, fline, dostat;

--- 27,33 -----
  {
  	register struct message *mp;
  	register int t;
! 	long c;
  	FILE *ibuf;
  	char line[LINESIZE], field[BUFSIZ];
  	int lc, ishead, infld, fline, dostat;
***************
*** 36,42
  
  	mp = mailp;
  	ibuf = setinput(mp);
! 	c = msize(mp);
  	ishead = 1;
  	dostat = 1;
  	infld = 0;

--- 36,42 -----
  
  	mp = mailp;
  	ibuf = setinput(mp);
! 	c = mp->m_size;
  	ishead = 1;
  	dostat = 1;
  	infld = 0;
***************
*** 43,49
  	fline = 1;
  	lc = 0;
  	clearerr(obuf);
! 	while (c > 0) {
  		fgets(line, LINESIZE, ibuf);
  		c -= strlen(line);
  		lc++;

--- 43,49 -----
  	fline = 1;
  	lc = 0;
  	clearerr(obuf);
! 	while (c > 0L) {
  		fgets(line, LINESIZE, ibuf);
  		c -= (long)strlen(line);
  		lc++;
***************
*** 45,51
  	clearerr(obuf);
  	while (c > 0) {
  		fgets(line, LINESIZE, ibuf);
! 		c -= strlen(line);
  		lc++;
  		if (ishead) {
  			/* 

--- 45,51 -----
  	clearerr(obuf);
  	while (c > 0L) {
  		fgets(line, LINESIZE, ibuf);
! 		c -= (long)strlen(line);
  		lc++;
  		if (ishead) {
  			/* 

vars.c:
*** vars.c.orig	Fri Aug  9 01:31:13 1985
--- vars.c	Fri Aug  9 02:49:17 1985
***************
*** 107,113
  
  	if (equal(str, ""))
  		return("");
! 	top = calloc(strlen(str)+1, 1);
  	cp = top;
  	cp2 = str;
  	while (*cp++ = *cp2++)

--- 107,114 -----
  
  	if (equal(str, ""))
  		return("");
! 	if ((top = calloc(strlen(str)+1, 1) == NULL)
! 		panic ("Out of memory");
  	cp = top;
  	cp2 = str;
  	while (*cp++ = *cp2++)

hdr/def.h:
*** hdr/def.h.orig	Fri Aug  9 01:30:29 1985
--- hdr/def.h	Fri Aug  9 14:03:03 1985
***************
*** 36,42
  	short	m_flag;			/* flags, see below */
  	short	m_block;		/* block number of this message */
  	short	m_offset;		/* offset in block of message */
! 	unsigned	m_size;		/* Bytes in the message */
  	short	m_lines;		/* Lines in the message */
  };
  

--- 36,42 -----
  	short	m_flag;			/* flags, see below */
  	short	m_block;		/* block number of this message */
  	short	m_offset;		/* offset in block of message */
! 	long	m_size;			/* Bytes in the message */
  	short	m_lines;		/* Lines in the message */
  };
  
***************
*** 292,295
  struct	name	*usermap();
  struct	name	*verify();
  struct	var	*lookup();
- unsigned	int	msize();

--- 292,294 -----
  struct	name	*usermap();
  struct	name	*verify();
  struct	var	*lookup();

guy@sun.uucp (Guy Harris) (08/13/85)

There were a couple of problems with the bug fixes posted earlier (the mail
I'm running has a rather complicated history so sticking the fixes back into
more vanilla versions of Mail/mailx caused a couple of errors).  The fixes
should be obvious, but here they are anyway:

*** aux.c.broken	Fri Aug  9 14:04:24 1985
--- aux.c	Mon Aug 12 10:47:46 1985
***************
*** 528,533
  {
  	register int c;
  	register char *cp, *cp2;
  	int gotlt, lastsp;
  	char nbuf[BUFSIZ];
  	int nesting;

--- 528,534 -----
  {
  	register int c;
  	register char *cp, *cp2;
+ 	char *bufend;
  	int gotlt, lastsp;
  	char nbuf[BUFSIZ];
  	int nesting;

*** vars.c.broken	Fri Aug  9 02:49:17 1985
--- vars.c	Mon Aug 12 11:29:10 1985
***************
*** 107,113
  
  	if (equal(str, ""))
  		return("");
! 	if ((top = calloc(strlen(str)+1, 1) == NULL)
  		panic ("Out of memory");
  	cp = top;
  	cp2 = str;

--- 107,113 -----
  
  	if (equal(str, ""))
  		return("");
! 	if ((top = calloc(strlen(str)+1, 1)) == NULL)
  		panic ("Out of memory");
  	cp = top;
  	cp2 = str;

	Guy Harris

levy@ttrdc.UUCP (Daniel R. Levy) (08/15/85)

In article <2617@sun.uucp>, guy@sun.uucp (Guy Harris) writes:
>There were a couple of problems with the bug fixes posted earlier (the mail
>I'm running has a rather complicated history so sticking the fixes back into
>more vanilla versions of Mail/mailx caused a couple of errors).  The fixes
>should be obvious, but here they are anyway:
>
> ...
>
>*** vars.c.broken	Fri Aug  9 02:49:17 1985
>--- vars.c	Mon Aug 12 11:29:10 1985
>***************
>*** 107,113
> ...
>! 	if ((top = calloc(strlen(str)+1, 1) == NULL)
> ...
>
>	Guy Harris

Boy, it IS broken!  The parentheses don't even balance.  (Four left ones
against three right ones.)  How did the sucker even compile, let alone
fail?  (Or are these fixes to the "fixes"?)  Sorry if this is a duhhhhmb
question.
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer, my pets, my plants, my boss, or the
| at&t computer systems division |  s.a. of any computer upon which I may hack.
|        skokie, illinois        |
|          "go for it"           |  Path: ..!ihnp4!ttrdc!levy
 --------------------------------     or: ..!ihnp4!iheds!ttbcad!levy