qingdoa daoo : msvcrt: Allow environment strings longer than 512 characters .

Alexandre Julliard julliard at wine.codeweavers.com
Mon Apr 3 05:34:00 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 35a9398ffecba8205156639a32493ea294801fb5
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=35a9398ffecba8205156639a32493ea294801fb5

Author: qingdoa daoo <qingdao33122 at yahoo.com>
Date:   Mon Apr  3 00:31:12 2006 -0700

msvcrt: Allow environment strings longer than 512 characters.

---

 dlls/msvcrt/environ.c       |   41 +++++++++++++++++++++++++++++++----------
 dlls/msvcrt/tests/environ.c |   22 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c
index 0a49916..c59cd75 100644
--- a/dlls/msvcrt/environ.c
+++ b/dlls/msvcrt/environ.c
@@ -73,20 +73,28 @@ MSVCRT_wchar_t *_wgetenv(const MSVCRT_wc
  */
 int _putenv(const char *str)
 {
- char name[256], value[512];
- char *dst = name;
+ char *name, *value;
+ char *dst;
  int ret;
 
  TRACE("%s\n", str);
 
  if (!str)
    return -1;
+   
+ name = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1);
+ if (!name)
+   return -1;
+ dst = name;
  while (*str && *str != '=')
   *dst++ = *str++;
  if (!*str++)
-   return -1;
- *dst = '\0';
- dst = value;
+ {
+   ret = -1;
+   goto finish;
+ }
+ *dst++ = '\0';
+ value = dst;
  while (*str)
   *dst++ = *str++;
  *dst = '\0';
@@ -101,6 +109,9 @@ int _putenv(const char *str)
    _environ = msvcrt_SnapshotOfEnvironmentA(_environ);
  if (_wenviron)
    _wenviron = msvcrt_SnapshotOfEnvironmentW(_wenviron);
+   
+finish:
+ HeapFree(GetProcessHeap(), 0, name);
  return ret;
 }
 
@@ -109,20 +120,27 @@ int _putenv(const char *str)
  */
 int _wputenv(const MSVCRT_wchar_t *str)
 {
- MSVCRT_wchar_t name[256], value[512];
- MSVCRT_wchar_t *dst = name;
+ MSVCRT_wchar_t *name, *value;
+ MSVCRT_wchar_t *dst;
  int ret;
 
  TRACE("%s\n", debugstr_w(str));
 
  if (!str)
    return -1;
+ name = HeapAlloc(GetProcessHeap(), 0, (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t));
+ if (!name)
+   return -1;
+ dst = name;
  while (*str && *str != '=')
   *dst++ = *str++;
  if (!*str++)
-   return -1;
- *dst = 0;
- dst = value;
+ {
+   ret = -1;
+   goto finish;
+ }
+ *dst++ = 0;
+ value = dst;
  while (*str)
   *dst++ = *str++;
  *dst = 0;
@@ -137,5 +155,8 @@ int _wputenv(const MSVCRT_wchar_t *str)
    _environ = msvcrt_SnapshotOfEnvironmentA(_environ);
  if (_wenviron)
    _wenviron = msvcrt_SnapshotOfEnvironmentW(_wenviron);
+
+finish:
+ HeapFree(GetProcessHeap(), 0, name);
  return ret;
 }
diff --git a/dlls/msvcrt/tests/environ.c b/dlls/msvcrt/tests/environ.c
index 87355bc..661a8b5 100644
--- a/dlls/msvcrt/tests/environ.c
+++ b/dlls/msvcrt/tests/environ.c
@@ -21,6 +21,27 @@
 #include "wine/test.h"
 #include <stdlib.h>
 
+static const char *a_very_long_env_string =
+ "LIBRARY_PATH="
+ "C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/;"
+ "C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/;"
+ "/mingw/lib/gcc/mingw32/3.4.2/;"
+ "/usr/lib/gcc/mingw32/3.4.2/;"
+ "C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/lib/mingw32/3.4.2/;"
+ "C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/lib/;"
+ "/mingw/mingw32/lib/mingw32/3.4.2/;"
+ "/mingw/mingw32/lib/;"
+ "/mingw/lib/mingw32/3.4.2/;"
+ "/mingw/lib/;"
+ "C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../mingw32/3.4.2/;"
+ "C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../;"
+ "/mingw/lib/mingw32/3.4.2/;"
+ "/mingw/lib/;"
+ "/lib/mingw32/3.4.2/;"
+ "/lib/;"
+ "/usr/lib/mingw32/3.4.2/;"
+ "/usr/lib/";
+
 START_TEST(environ)
 {
     ok( _putenv("cat=") == 0, "_putenv failed on deletion of nonexistent environment variable\n" );
@@ -30,6 +51,7 @@ START_TEST(environ)
 
     ok( _putenv("=") == -1, "should not accept '=' as input\n" );
     ok( _putenv("=dog") == -1, "should not accept '=dog' as input\n" );
+    ok( _putenv(a_very_long_env_string) == 0, "_putenv failed for long environment string\n");
 
     ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" );
 }




More information about the wine-cvs mailing list