Re: Cleansing the environment automatically

Eli Zaretskii <[email protected]>
Newsgroups gmane.comp.gnu.make.windows
Message-ID <[email protected]>
[Moved to make-w32, as this is now a discussion about a bug.]

> Date: Sat, 19 Jan 2008 11:14:36 +0200
> From: Eli Zaretskii <[email protected]>
> Cc: [email protected]
> 
> > Date: Sat, 19 Jan 2008 04:26:49 +0000
> > From: Greg Chicares <[email protected]>
> > Cc: David Wuertele <[email protected]>, [email protected]
> > 
> > On 2008-01-19 03:17Z, Paul Smith wrote:
> > > On Sat, 2008-01-19 at 01:09 +0000, David Wuertele wrote:
> > >> I always try to create a more strict configuration hygiene by
> > >> cleansing the environment using "env -i" at the beginning of each
> > >> command.
> > [...]
> > >         unexport $(.VARIABLES)
> > 
> > I tried that with this testcase, using a msw binary I'd built
> > myself from FSF make-3.81 sources, and got a segfault:
> > 
> > C:/tmp[0]$cat env_i.make
> > unexport $(.VARIABLES)
> > 
> > all:
> > 	@echo xyzzy is $$xyzzy
> > C:/tmp[0]$make -f env_i.make
> > \usr\bin\make.EXE: Interrupt/Exception caught (code = 0xc0000005, addr = 0x419fc0)
> 
> I see this on Windows as well, but on GNU/Linux the above testcase
> does not cause a crash.  I will try to look into this

The reason is the fact that on Windows, $SHELL is not normally set in
the environment when Make is invoked.  This causes shell_var to remain
unset, and "unexport" exposes this bug because it tries to use the
value of shell_var.

I propose the following fix; if no one objects in a week, I will
install it in CVS.


2008-01-19  Eli Zaretskii  <[email protected]>

	* variable.c (target_environment): Don't use shell_var if its
	`value' field is NULL.


--- variable.c~4	2007-10-13 12:15:27.995750000 +0200
+++ variable.c	2008-01-19 12:00:18.101750000 +0200
@@ -916,15 +916,18 @@ target_environment (struct file *file)
 		break;
 
 	      case v_noexport:
-                /* If this is the SHELL variable and it's not exported, then
-                   add the value from our original environment.  */
-                if (streq (v->name, "SHELL"))
-                  {
-                    extern struct variable shell_var;
-                    v = &shell_var;
-                    break;
-                  }
-                continue;
+		{
+		  /* If this is the SHELL variable and it's not exported,
+		     then add the value from our original environment, if
+		     the original environment defined a value for SHELL.  */
+		  extern struct variable shell_var;
+		  if (streq (v->name, "SHELL") && shell_var.value)
+		    {
+		      v = &shell_var;
+		      break;
+		    }
+		  continue;
+		}
 
 	      case v_ifset:
 		if (v->origin == o_default)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.