Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!decvax!tektronix!cae780!hubble From: hubble@cae780.TEK.COM (Larry Hubble) Newsgroups: comp.os.minix Subject: Bug in library routine getenv() Message-ID: <3860@cae780.TEK.COM> Date: Sun, 3-May-87 04:15:15 EDT Article-I.D.: cae780.3860 Posted: Sun May 3 04:15:15 1987 Date-Received: Sun, 3-May-87 19:39:14 EDT Reply-To: hubble@cae780.UUCP (Larry Hubble) Organization: Tektronix/CAE Systems, Santa Clara, CA Lines: 21 Keywords: Bug, Fix, getenv Summary: getenv() loops infinitely if you don't want the first environ variable The library routine getenv() has a bug in it. If the environment variable you are requesting does not happen to be the first one in the environment table, getenv() goes into an infinite loop. The fix is very simple. The first executable line is: while ((p = *v) != NULL) { It should be: while ((p = *v++) != NULL) { Getenv() then seems to work properly. I believe there is also a bug in the library routine strncpy -- it doesn't null terminate the string if the string to copy is really longer that "n" characters. I have not verified or fixed this yet, but will post it when I get a chance to cure it. --------------------------------------------------------------------------- Larry R. Hubble Tektronix/CAE Systems Division (408) 748-4782 5302 Betsy Ross Dr. {hplabs,tektronix}hubble@cae780 Santa Clara, CA 95054