X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f Sender: rich AT phekda DOT freeserve DOT co DOT uk Message-ID: <3C4AB07C.AF998177@phekda.freeserve.co.uk> Date: Sun, 20 Jan 2002 11:56:44 +0000 From: Richard Dawe X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.19 i586) X-Accept-Language: de,fr MIME-Version: 1.0 To: djgpp-workers AT delorie DOT com Subject: Re: env.exe crash - reproducible test program References: <10201180538 DOT AA24590 AT clio DOT rice DOT edu> <3C495559 DOT C01A23AF AT phekda DOT freeserve DOT co DOT uk> <3099-Sat19Jan2002144449+0200-eliz AT is DOT elta DOT co DOT il> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Hello. Eli Zaretskii wrote: > To clarify: what this comment _really_ wants to tell is that the > original environ, the one putenv sees on its very first call, _must_ > be malloc'ed. Once the first call was made (typically, by the > startup code), it is okay to do what the test program did, > i.e. replace environ with a non-malloc'ed array. > > It's quite possible that this explains the cause for the: If having > $DJGPP undefined prevents putenv from being called during startup > even once, putenv will indeed be unable to cope with such code. Yes, this seems to be the case, looking at __crt0_load_environment_file in src/libc/crt0/c1loaddef.c. > This suggests a solution: add a dummy putenv call to the startup > code, which will be called unconditionally. Yes, this works. There's a patch below. Do you think this code should be in crt1.c instead of this function or is it OK where it is? OK to commit? Eli, would you still like YAMD versions of Charles's test programs? I don't think there's any memory corruption going on (see other mail). 'environ' did not get set to any unexpected values when I tested using gdb watchpoints (watch environ !=
). But I can provide you with test images, if you'd like. Thanks, bye, Rich =] -- Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ] Index: c1loadef.c =================================================================== RCS file: /cvs/djgpp/djgpp/src/libc/crt0/c1loadef.c,v retrieving revision 1.5 diff -p -u -3 -r1.5 c1loadef.c --- c1loadef.c 1999/06/03 17:27:35 1.5 +++ c1loadef.c 2002/01/20 11:51:22 @@ -1,3 +1,4 @@ +/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ @@ -10,12 +11,23 @@ #include #include #include +#include void __crt0_load_environment_file(char *app_name) { int djgpp_env; char *djgpp_var = getenv("DJGPP"); + + /* + * Call putenv so that its static counters are computed. If this + * is not done, programs that manipulate `environ' directly will crash, + * when `DJGPP' is not set in the environment. + * + * Use putenv to delete an environment variable with a name that is + * unlikely to be used. + */ + putenv(unconst("DJGPP_sillynametohaveforanenvironmentvariable", char *)); if (djgpp_var) {