Subject: bug#2062 closed by Juanma Barranquero <[email-masked]> (Re: bug#2062: PATH can contain non-expanded variables)

From: [email-masked] (Emacs bug Tracking System)
Date: Wed, 28 Jan 2009 15:15:03 +0000

This is an automatic notification regarding your bug report
which was filed against the emacs,w32 package:

#2062: PATH can contain non-expanded variables

It has been closed by Juanma Barranquero <[email-masked]>.

Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Juanma Barranquero <[email-masked]> by
replying to this email.

-- 
2062: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=2062
Emacs Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#2062: PATH can contain non-expanded variables
From: Juanma Barranquero <[email-masked]>
To: Stefan Monnier <[email-masked]>
Cc: [email-masked], Eli Zaretskii <[email-masked]>, [email-masked]
Date: Wed, 28 Jan 2009 16:07:03 +0100

On Wed, Jan 28, 2009 at 15:24, Stefan Monnier <[email-masked]> wrote:

> So your patch works around a bug in some other place which fails to
> expand PATH.

Not only you're right, but I know which program is causing the problem. Thanks!

According to MSDN KB 837633 (and other sources):

  Windows XP adds the path value, if it exists, to the PATH
environment variable,
  if you use the ShellExecute() function to start your program.

So, correctly, Windows Explorer uses App Paths, and CMD.EXE does not
(I've checked it).

The problem is with TCC (formerly 4NT), a proprietary command shell I
use. I had mistakenly assumed that TCC worked like CMD (or, in fact, I
did the reverse: because TCC adds App Paths to PATH, I assumed that
CMD also did it).

But it is not: apparently, TCC is adding App Paths to PATH (which is
either a bug or a feature, depending of one's POV), but it's not
taking into account that the App Paths entry can be REG_EXPAND_SZ (and
that's definitely a bug).

I'll report it to them.

    Juanma

Subject: PATH can contain non-expanded variables
From: Juanma Barranquero <[email-masked]>
To: Emacs Bug Tracker <[email-masked]>
Date: Mon, 26 Jan 2009 14:00:15 +0100

Package: emacs,w32
Version: 23.0.60

It is possible for PATH (or other path-like variables, like EMACSPATH
and EMACSLOADPATH) to contain unexpanded variables:

ELISP> exec-path
("c:/emacs/bin" "%MYTEST%" "C:/WINDOWS/system32" "C:/WINDOWS"
"C:/WINDOWS/system32/Wbem" "c:/emacs/trunk/bin")

for example, if the user has set
"HKLM\Microsoft\Windows\CurrentVersion\App Paths\emacs.exe\Path" as a
REG_EXPAND_SZ.

These variables should be expanded, but currently
emacs.c:decode_env_path does not. The following patch fixes it.

Comments?

    Juanma

Index: emacs.c
===================================================================
RCS file: /sources/emacs/emacs/src/emacs.c,v
retrieving revision 1.461
diff -u -2 -r1.461 emacs.c
--- emacs.c	23 Jan 2009 14:53:11 -0000	1.461
+++ emacs.c	26 Jan 2009 12:48:49 -0000
@@ -2467,6 +2467,12 @@
   if (path)
     {
+#ifdef WINDOWSNT
+      DWORD required = ExpandEnvironmentStrings (path, NULL, 0);
+      p = (char *) alloca (required);
+      ExpandEnvironmentStrings (path, p, required);
+#else
       p = alloca (strlen (path) + 1);
       strcpy (p, path);
+#endif
       path = p;