delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/01/20/11:00:10

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: <3C4AE979.42DFF068@phekda.freeserve.co.uk>
Date: Sun, 20 Jan 2002 15:59:53 +0000
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
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: <Pine DOT SUN DOT 3 DOT 91 DOT 1020120140406 DOT 9986F-100000 AT is>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Eli Zaretskii wrote:
> 
> On Sun, 20 Jan 2002, Richard Dawe wrote:
> >  void
> >  __crt0_load_environment_file(char *app_name)
> >  {
> 
> I think this should go into crt1.c, not c1loadef.c.  That's because the
> latter could be excluded from a program if the user defines an empty
> __crt0_load_environment_file in her program (e.g., to minimize the
> footprint).

OK.
 
> > +   * Use putenv to delete an environment variable with a name that is
> > +   * unlikely to be used.
> > +   */
> > +  putenv(unconst("DJGPP_sillynametohaveforanenvironmentvariable", char *));
> 
> Doesn't it work to say just
> 
>      putenv("");
> 
> ?  That would do the trick without putting extraneous variables into the
> environment.  Remember: all we need is for putenv to record the value of
> `environ'.

Well, originally I was trying to use putenv in a POSIX compatible way, but
putenv without an assignment is invalid. So now the patch does as you suggest.

Please find below a revised patch, with WC entry. OK to commit?

Thanks, bye, Rich =]

-- 
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]

Index: src/libc/crt0/crt1.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/crt0/crt1.c,v
retrieving revision 1.7
diff -p -u -3 -r1.7 crt1.c
--- src/libc/crt0/crt1.c        2001/09/24 21:13:18     1.7
+++ src/libc/crt0/crt1.c        2002/01/20 15:56:52
@@ -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) 1998 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
@@ -19,6 +20,7 @@
 #include <unistd.h>
 #include <libc/environ.h>
 #include <dos.h> /* for _osmajor/_osminor */
+#include <libc/unconst.h>
 
 /* Global variables */
 
@@ -150,6 +152,13 @@ setup_environment(void)
     cp++; /* skip to next character */
   } while (*cp); /* repeat until two NULs */
   environ[env_count] = 0;
+
+  /*
+   * 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.
+   */
+  putenv(unconst("", char *));
   
   __dos_argv0 = (char *)malloc(strlen(cp + 3)+1);
   if (__dos_argv0 == 0)
Index: src/docs/kb/wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.105
diff -p -u -3 -r1.105 wc204.txi
--- src/docs/kb/wc204.txi       2001/12/24 02:01:45     1.105
+++ src/docs/kb/wc204.txi       2002/01/20 15:56:56
@@ -703,3 +703,8 @@ modified, so that it can be built agains
 
 @findex strftime AT r{, and z format}
 Corrected problem with negative gmt offsets with z format in @code{strftime}.
+
+@vindex DJGPP AT r{, environment variable and memory corruption}
+@cindex startup code, and memory corruption
+The startup code was updated, to prevent memory corruption when
+the @code{DJGPP} environment variable is not set.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019