[7615] in Athena Bugs

home help back first fref pref prev next nref lref last post

NeXT Mach 2.1: /bin/login environment handling code

daemon@ATHENA.MIT.EDU (Mark W. Eichin)
Sat Jun 1 13:15:47 1991

Date: Sat, 1 Jun 91 13:15:27 EDT
From: "Mark W. Eichin" <eichin@MIT.EDU>
To: bugs@MIT.EDU
Cc: erikkay@MIT.EDU

System type, version:	NeXT Mach 2.1
System name:		milo.mit.edu
What's wrong:
	1) /source/athena/bin/login/login.c fails to copy a NULL into
the end of the copy of the environment that it makes. This breaks the
NeXT in particular because the space used by the copy of environ
happens to fall into a block that was freed by something else, and is
thus not already zeroed.
	2) things which are in string.h and other standard headers
should not be *incorrectly* declared in the source.
	3) setenv takes three arguments - it should be called with
three... particularly when setting KRB_ENVIRON.

What should have happened:
	The following parts of a diff should be applied... your line
numbers may vary since I elided irrelevant sections. The pieces below
correspond to 2, 1, and 3 above. 
	The fix to (1) has the advantage of being more readable than
the existing code, as well as being correct; it is the patch that
matters particularly.

				_Mark_ <eichin@athena.mit.edu>
				MIT Student Information Processing Board

*** /tmp/login.c	Sat Jun  1 10:38:06 1991
--- /source/athena/bin/login/login.c	Thu Mar  7 13:48:56 1991
***************
*** 182,188 ****
  
  struct	passwd *pwd;
  struct	passwd *hes_getpwnam();
! /* char	*strcat(), *rindex(), *index(), *malloc(), *realloc(); */
  int	timedout();
  char	*ttyname();
  char	*crypt();
--- 184,190 ----
  
  struct	passwd *pwd;
  struct	passwd *hes_getpwnam();
! char	*strcat(), *rindex(), *index(), *malloc(), *realloc();
  int	timedout();
  char	*ttyname();
  char	*crypt();
***************
*** 382,395 ****
      while (environ[i] != NULL)
  	i++;
      envnew = (char **) malloc(sizeof (char *) * (i + 1));
!     for (j=0, i=0; environ[i] == 0; i++, j++) {
  #ifdef _I386
  
  	if(strncmp(environ[i], "INIT", 4) == 0) continue;
  #endif
! 	envnew[j] = environ[i];
      }
-     envnew[j] = environ[i];	/* == 0 */
      environ = envnew;
  
      t = 0;
--- 383,396 ----
      while (environ[i] != NULL)
  	i++;
      envnew = (char **) malloc(sizeof (char *) * (i + 1));
!     for (j=0; i >= 0; i--) {
! 	if(!environ[i]) continue;
  #ifdef _I386
  
  	if(strncmp(environ[i], "INIT", 4) == 0) continue;
  #endif
! 	envnew[j++] = environ[i];
      }
      environ = envnew;
  
      t = 0;
***************
*** 453,459 ****
  	    strncat(tkfile, rindex(ttyn, '/')+1,
  		    sizeof(tkfile) - strlen(tkfile));
  	    (void) unlink (tkfile);
! 	    setenv(KRB_ENVIRON, tkfile, 1);
  	    
  	    setpriority(PRIO_PROCESS, 0, -4);
  	    pp = getlongpass("Password:");
--- 454,460 ----
  	    strncat(tkfile, rindex(ttyn, '/')+1,
  		    sizeof(tkfile) - strlen(tkfile));
  	    (void) unlink (tkfile);
! 	    setenv(KRB_ENVIRON, tkfile);
  	    
  	    setpriority(PRIO_PROCESS, 0, -4);
  	    pp = getlongpass("Password:");

home help back first fref pref prev next nref lref last post