fix to sendmail / save _environ pointer

louie at umd5.UUCP louie at umd5.UUCP
Sat Mar 2 09:18:09 AEST 1985


Here's a fix to a bug in sendmail that (among other things) causes
the getenv() function to die with a segmentation error.  The problem
stems from using frozen configuration files.  Here's what happens:
When the /usr/lib/sendmail.fc frozen file is made, all of bss (from
_edata on) is written out.  The first word of bss (at least on our PDP11)
is the _environ pointer.  When the frozen file is restored, the new
instance of sendmail running with someone else's environment gets its
_environ pointer blasted.

The simple fix is to save and restore _environ around the read of the
frozen file into bss.

This was detected and fixed on a PDP11/44, running 2.9BSD.  I'm not sure
if this is a problem for 4.[12] on a VAX, but if the environ pointer is
in bss, then you better take a look.

This is a diff -c comparison.  main.c~ is the old file.  These differences
are in the thaw() subroutine in main.c

*** main.c~	Fri Dec  9 05:07:50 1983
--- main.c	Fri Mar  1 17:44:43 1985
***************
*** 803,808
  	union frz fhdr;
  	extern char edata;
  	extern char Version[];
  
  	if (freezefile == NULL)
  		return (FALSE);

--- 810,817 -----
  	union frz fhdr;
  	extern char edata;
  	extern char Version[];
+ 	extern char **environ;
+ 	char	**envsave;
  
  	if (freezefile == NULL)
  		return (FALSE);
***************
*** 830,835
  		(void) close(f);
  		return (FALSE);
  	}
  
  	/* now read in the freeze file */
  	if (read(f, (char *) &edata, fhdr.frzinfo.frzbrk - &edata) !=

--- 839,852 -----
  		(void) close(f);
  		return (FALSE);
  	}
+ /**
+  **  Arrrrg!  Since the pointer to the environment is in BSS, and our
+  **  bss get's blasted over when the freeze file is read in, we need to 
+  **  save and restore the environ pointer for getenv()
+  **/
+ 	envsave = environ;		/* save pointer to environment */
  
  	/* now read in the freeze file */
  	if (read(f, (char *) &edata, fhdr.frzinfo.frzbrk - &edata) !=
***************
*** 839,845
  		write(2, "Cannot read freeze file\n", 24);
  		_exit(EX_SOFTWARE);
  	}
! 
  	(void) close(f);
  	return (TRUE);
  }

--- 856,864 -----
  		write(2, "Cannot read freeze file\n", 24);
  		_exit(EX_SOFTWARE);
  	}

! 	environ = envsave;

  	(void) close(f);
  	return (TRUE);
  }
-- 

Louis A. Mamakos  WA3YMH
Computer Science Center - Systems Programming
University of Maryland, College Park

Internet: louie at umd5.arpa
UUCP: ..!{seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!louie



More information about the Comp.unix.wizards mailing list