4.2BSD rmail fixes

Geoffrey Collyer geoff at utcsstat.UUCP
Sun Apr 1 22:44:36 AEST 1984


The 4.2BSD rmail has a number of bugs.

It wastes 512 bytes on a scanf argument rather than using %*s.
(All the world's a VAX, I guess.)

It originally allowed `From a!b!user date' without `remote from sys'
and therefore greatly increased the probability of misinterpreting
a body line starting with From as part of the postmark (e.g. a
"forwarded by" line generated by /bin/mail (wazzat?)).  Ever seen
a return address like `foo!somewhere!bar!aps'?  They are caused by
this bit of brain-damage.  We nuked it utterly.

rmail now checks fgets and sscanf return values and exits if EOF
or too few matches.  If you have ever seen your rmail looping
infinitely (we have), this may be the cause.  Feeding null input
to rmail will make it loop.

Henry Spencer (utzoo!henry) helped find and fix these.
As usual, honey danber probably fixes these better than we have.

Diffs follow. Lines numbers are approximate and may vary.
----
35d30
< 	register char *uf;	/* ptr into ufrom */
41d35
< 	char junk[512];	/* scratchpad */
58,60c52
< 
< 	for (;;) {
< 		(void) fgets(lbuf, sizeof lbuf, stdin);
---
> 	while (fgets(lbuf, sizeof lbuf, stdin) != NULL) {
64,79c56
< 		(void) sscanf(lbuf, "%s %s", junk, ufrom);
< 		cp = lbuf;
< 		uf = ufrom;
< 		for (;;) {
< 			cp = index(cp+1, 'r');
< 			if (cp == NULL) {
< 				register char *p = rindex(uf, '!');
< 
< 				if (p != NULL) {
< 					*p = '\0';
< 					(void) strcpy(sys, uf);
< 					uf = p + 1;
< 					break;
< 				}
< 				cp = "remote from somewhere";
< 			}
---
> 		for (cp = index(lbuf, 'r'); cp != NULL; cp = index(cp+1, 'r')) {
87,88c64,69
< 		if (cp != NULL)
< 			(void) sscanf(cp, "remote from %s", sys);
---
> 		if (cp == NULL)		/* "remote" missing */
> 			break;
> 		if (sscanf(cp, "remote from %s", sys) < 1)
> 			break;
> 		if (sscanf(lbuf, "%*s %s", ufrom) < 1)
> 			break;
94c75
< 				uf, sys, from);
---
> 				ufrom, sys, from);
97c78
< 	(void) strcat(from, uf);
---
> 	(void) strcat(from, ufrom);

Geoff Collyer, U. of Toronto



More information about the Comp.unix.wizards mailing list