[comp.windows.x] Xterm and utmpInhibit

jfc@ATHENA.MIT.EDU (John Carr) (01/06/90)

This is cc-ed to xpert as I have seen this problem reported there.

Program:
	xterm in R4 release

Problem:
	When the "utmpInhibit" resource is turned on, xterm exits with
	no error message.

Details:
	The initgroups() call in clients/xterm/main.c derefecences
	the variable "pw" (a struct passwd *) without checking that
	it is non-NULL.  This causes the child of xterm to die, and
	the xterm process itself to exit when utmpInhibit is true or
	the user's id can not be converted to a username.

Environment:
	IBM RT running 4.3.  Should happen on any system with
	utmp and HAS_BSD_GROUPS defined.

Fix:

*** /tmp/,RCSt1000336	Fri Jan  5 17:48:17 1990
--- main.c	Thu Jan  4 18:07:33 1990
***************
*** 1781,1788 ****
  		tslot = ttyslot();
  		added_utmp_entry = False;
  		{
! 			if (!resource.utmpInhibit &&
! 			    (pw = getpwuid(screen->uid)) &&
  			    (i = open(etc_utmp, O_WRONLY)) >= 0) {
  				bzero((char *)&utmp, sizeof(struct utmp));
  				(void) strncpy(utmp.ut_line,
--- 1781,1788 ----
  		tslot = ttyslot();
  		added_utmp_entry = False;
  		{
! 			if ((pw = getpwuid(screen->uid)) &&
! 			    !resource.utmpInhibit &&
  			    (i = open(etc_utmp, O_WRONLY)) >= 0) {
  				bzero((char *)&utmp, sizeof(struct utmp));
  				(void) strncpy(utmp.ut_line,
***************
*** 1852,1858 ****
  
  		(void) setgid (screen->gid);
  #ifdef HAS_BSD_GROUPS
! 		if (geteuid() == 0)
  		  initgroups (pw->pw_name, pw->pw_gid);
  #endif
  		(void) setuid (screen->uid);
--- 1852,1858 ----
  
  		(void) setgid (screen->gid);
  #ifdef HAS_BSD_GROUPS
! 		if(pw && geteuid() == 0)
  		  initgroups (pw->pw_name, pw->pw_gid);
  #endif
  		(void) setuid (screen->uid);


  --John Carr (jfc@athena.mit.edu)
  Project Athena Systems Development