Bruno Jesus : cmd: Ensure environment variables fit in memory.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Jan 6 15:05:17 CST 2015


Module: wine
Branch: master
Commit: 5a469f1b87e58fd96dfb68f1e892c0d3cae5a97b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5a469f1b87e58fd96dfb68f1e892c0d3cae5a97b

Author: Bruno Jesus <00cpxxx at gmail.com>
Date:   Tue Jan  6 14:55:01 2015 -0200

cmd: Ensure environment variables fit in memory.

---

 programs/cmd/batch.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 294a153..1a78b55 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -496,15 +496,23 @@ void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute)
     WCHAR *begin = strchrW(firstModifier, '$') + 1;
     WCHAR *end   = strchrW(firstModifier, ':');
     WCHAR env[MAX_PATH];
-    WCHAR fullpath[MAX_PATH];
+    DWORD size;
 
     /* Extract the env var */
     memcpy(env, begin, (end-begin) * sizeof(WCHAR));
     env[(end-begin)] = 0x00;
 
-    /* If env var not found, return empty string */
-    if ((GetEnvironmentVariableW(env, fullpath, MAX_PATH) == 0) ||
-        (SearchPathW(fullpath, outputparam, NULL, MAX_PATH, outputparam, NULL) == 0)) {
+    size = GetEnvironmentVariableW(env, NULL, 0);
+    if (size > 0) {
+      WCHAR *fullpath = heap_alloc(size * sizeof(WCHAR));
+      if (!fullpath || (GetEnvironmentVariableW(env, fullpath, size) == 0) ||
+          (SearchPathW(fullpath, outputparam, NULL, MAX_PATH, outputparam, NULL) == 0))
+          size = 0;
+      heap_free(fullpath);
+    }
+
+    if (!size) {
+      /* If env var not found, return empty string */
       finaloutput[0] = 0x00;
       outputparam[0] = 0x00;
       skipFileParsing = TRUE;




More information about the wine-cvs mailing list