[PATCH 6/6] CMD.exe: Fix bug 8346, handling of malformed environment variable expansion

Jason Edmeades us at edmeades.me.uk
Mon May 7 09:05:57 CDT 2007


Although the syntax is invalid, try to handle this specific case as per
windows, but the whole area of malformed environment variable expansion
(ie %fred with the trailing % missing) seems flakey on windows, and so
its best to fix these on a case by case basis.

In this case, a % followed by no trailing % just gets removed
---
 programs/cmd/wcmdmain.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index eeeda33..6fc4135 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -1534,9 +1534,16 @@ static WCHAR *WCMD_expand_envvar(WCHAR *start) {
     /* Find the end of the environment variable, and extract name */
     endOfVar = strchrW(start+1, '%');
     if (endOfVar == NULL) {
-      /* FIXME: Some special conditions here depending on whether
+
+      /* In batch program, missing terminator for % and no following
+         ':' just removes the '%'                                   */
+      s = WCMD_strdupW(start + 1);
+      strcpyW (start, s);
+      free(s);
+
+      /* FIXME: Some other special conditions here depending on whether
          in batch, complex or not, and whether env var exists or not! */
-      return start+1;
+      return start;
     }
     lstrcpynW(thisVar, start, (endOfVar - start)+2); /* (lstrcpynW inserts null when truncating) */
     colonpos = strchrW(thisVar+1, ':');
-- 
1.5.0




More information about the wine-patches mailing list