[comp.bugs.4bsd] Mail dereferences null pointers. +Fix

gww@marduk.UUCP (Gary Winiger) (09/05/87)

Subject: Mail dereferences null pointers. +Fix
Index:	ucb/Mail 4.3BSD +Fix

Description:
	Both head.c and optim.c can cause null pointers to be dereferneced.
Repeat-By:
	Inspection of the code.  These happened some time ago, but I didn't
	get to posting them.  Now in the process of porting 4.3, I'm going
	back through all my 4.2 bug fixes.
Fix:
	The attached code corrects the problem at Elxsi.

Gary..
{ucbvax!sun,lll-lcc!lll-tis,amdahl!altos86,bridge2}!elxsi!gww
--------- cut --------- snip --------- :.,$w diff -------------
*** /tmp/,RCSt1001196	Fri Dec 19 17:56:40 1986
--- head.c	Fri Dec 19 17:56:18 1986
***************
*** 1,5 ****
--- 1,8 ----
  /*
   * $Log:	head.c,v $
+  * Revision 1.2  86/12/19  17:55:54  gww
+  * Get rid of null pointer references.
+  * 
   * Revision 1.1  86/12/19  17:40:09  gww
   * Initial revision
   * 
***************
*** 11,17 ****
   */
  
  #ifndef lint
! static char *ERcsId = "$Header: head.c,v 1.1 86/12/19 17:40:09 gww Exp $ ENIX BSD";
  static char *sccsid = "@(#)head.c	5.2 (Berkeley) 6/21/85";
  #endif not lint
  
--- 14,20 ----
   */
  
  #ifndef lint
! static char *ERcsId = "$Header: head.c,v 1.2 86/12/19 17:55:54 gww Exp $ ENIX BSD";
  static char *sccsid = "@(#)head.c	5.2 (Berkeley) 6/21/85";
  #endif not lint
  
***************
*** 95,101 ****
  	dp = nextword(cp, word);
  	if (!equal(word, ""))
  		hl->l_from = copyin(word, &sp);
! 	if (strncmp(dp, "tty", 3) == 0) {
  		cp = nextword(dp, word);
  		hl->l_tty = copyin(word, &sp);
  		if (cp != NOSTR)
--- 98,104 ----
  	dp = nextword(cp, word);
  	if (!equal(word, ""))
  		hl->l_from = copyin(word, &sp);
! 	if (dp && (strncmp(dp, "tty", 3) == 0)) {
  		cp = nextword(dp, word);
  		hl->l_tty = copyin(word, &sp);
  		if (cp != NOSTR)
***************
*** 295,310 ****
   */
  
  any(ch, str)
! 	char *str;
  {
  	register char *f;
! 	register c;
! 
! 	f = str;
! 	c = ch;
! 	while (*f)
! 		if (c == *f++)
! 			return(1);
  	return(0);
  }
  
--- 298,313 ----
   */
  
  any(ch, str)
! register char ch;
! register char *str;
  {
  	register char *f;
! 	if (f=str)
! 	{
! 		while (*f)
! 			if (ch == *f++)
! 				return(1);
! 	}
  	return(0);
  }

*** /tmp/,RCSt1001349	Fri Dec 19 18:31:45 1986
--- optim.c	Fri Dec 19 18:31:25 1986
***************
*** 1,5 ****
--- 1,8 ----
  /*
   * $Log:	optim.c,v $
+  * Revision 1.2  86/12/19  18:31:12  gww
+  * Get rid of null pointer reference.
+  * 
   * Revision 1.1  86/12/19  17:40:18  gww
   * Initial revision
   * 
***************
*** 11,17 ****
   */
  
  #ifndef lint
! static char *ERcsId = "$Header: optim.c,v 1.1 86/12/19 17:40:18 gww Exp $ ENIX BSD";
  static char *sccsid = "@(#)optim.c	5.5 (Berkeley) 11/2/85";
  #endif not lint
  
--- 14,20 ----
   */
  
  #ifndef lint
! static char *ERcsId = "$Header: optim.c,v 1.2 86/12/19 18:31:12 gww Exp $ ENIX BSD";
  static char *sccsid = "@(#)optim.c	5.5 (Berkeley) 11/2/85";
  #endif not lint
  
***************
*** 53,59 ****
  	if (cp == nbuf)
  		return(name);
  	*++cp = 0;
! 	strcat(nbuf, revarpa(name));
  	optim(nbuf, ret);
  	cp = revarpa(ret);
  	if (!icequal(name, cp))
--- 56,63 ----
  	if (cp == nbuf)
  		return(name);
  	*++cp = 0;
! 	if ((cp = revarpa(name)) != NOSTR)
! 		strcat(nbuf, cp);
  	optim(nbuf, ret);
  	cp = revarpa(ret);
  	if (!icequal(name, cp))
*** /tmp/,RCSt1001583	Thu Aug  6 17:13:02 1987
--- optim.c	Thu Aug  6 17:12:26 1987
***************
*** 1,5 ****
--- 1,8 ----
  /*
   * $Log:	optim.c,v $
+  * Revision 1.3  87/08/06  17:12:03  gww
+  * Get rid of another null pointer reference.
+  * 
   * Revision 1.2  86/12/19  18:31:12  gww
   * Get rid of null pointer reference.
   * 
***************
*** 14,20 ****
   */
  
  #ifndef lint
! static char *ERcsId = "$Header: optim.c,v 1.2 86/12/19 18:31:12 gww Exp $ ENIX BSD";
  static char *sccsid = "@(#)optim.c	5.5 (Berkeley) 11/2/85";
  #endif not lint
  
--- 17,23 ----
   */
  
  #ifndef lint
! static char *ERcsId = "$Header: optim.c,v 1.3 87/08/06 17:12:03 gww Exp $ ENIX BSD";
  static char *sccsid = "@(#)optim.c	5.5 (Berkeley) 11/2/85";
  #endif not lint
  
***************
*** 59,65 ****
  	if ((cp = revarpa(name)) != NOSTR)
  		strcat(nbuf, cp);
  	optim(nbuf, ret);
! 	cp = revarpa(ret);
  	if (!icequal(name, cp))
  		return(savestr(cp));
  	return(name);
--- 62,69 ----
  	if ((cp = revarpa(name)) != NOSTR)
  		strcat(nbuf, cp);
  	optim(nbuf, ret);
! 	if ((cp = revarpa(ret)) == NOSTR)
! 		return(name);
  	if (!icequal(name, cp))
  		return(savestr(cp));
  	return(name);