Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umd5.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!umcp-cs!cvl!umd5!louie From: louie@umd5.UUCP Newsgroups: net.mail,net.unix-wizards,net.bugs.2bsd,net.bugs.4bsd Subject: fix to sendmail / save _environ pointer Message-ID: <350@umd5.UUCP> Date: Fri, 1-Mar-85 18:18:09 EST Article-I.D.: umd5.350 Posted: Fri Mar 1 18:18:09 1985 Date-Received: Sun, 3-Mar-85 03:48:19 EST Distribution: net Organization: U of Md, CSC, College Park, Md Lines: 89 Xref: watmath net.mail:769 net.unix-wizards:12251 net.bugs.2bsd:235 net.bugs.4bsd:1416 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@umd5.arpa UUCP: ..!{seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!louie