msvcrt: Allow environment strings longer than 512 characters.

This commit is contained in:
qingdoa daoo 2006-04-03 00:31:12 -07:00 committed by Alexandre Julliard
parent 6a13925a16
commit 35a9398ffe
2 changed files with 53 additions and 10 deletions

View File

@ -73,20 +73,28 @@ MSVCRT_wchar_t *_wgetenv(const MSVCRT_wchar_t *name)
*/ */
int _putenv(const char *str) int _putenv(const char *str)
{ {
char name[256], value[512]; char *name, *value;
char *dst = name; char *dst;
int ret; int ret;
TRACE("%s\n", str); TRACE("%s\n", str);
if (!str) if (!str)
return -1; return -1;
name = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1);
if (!name)
return -1;
dst = name;
while (*str && *str != '=') while (*str && *str != '=')
*dst++ = *str++; *dst++ = *str++;
if (!*str++) if (!*str++)
return -1; {
*dst = '\0'; ret = -1;
dst = value; goto finish;
}
*dst++ = '\0';
value = dst;
while (*str) while (*str)
*dst++ = *str++; *dst++ = *str++;
*dst = '\0'; *dst = '\0';
@ -101,6 +109,9 @@ int _putenv(const char *str)
_environ = msvcrt_SnapshotOfEnvironmentA(_environ); _environ = msvcrt_SnapshotOfEnvironmentA(_environ);
if (_wenviron) if (_wenviron)
_wenviron = msvcrt_SnapshotOfEnvironmentW(_wenviron); _wenviron = msvcrt_SnapshotOfEnvironmentW(_wenviron);
finish:
HeapFree(GetProcessHeap(), 0, name);
return ret; return ret;
} }
@ -109,20 +120,27 @@ int _putenv(const char *str)
*/ */
int _wputenv(const MSVCRT_wchar_t *str) int _wputenv(const MSVCRT_wchar_t *str)
{ {
MSVCRT_wchar_t name[256], value[512]; MSVCRT_wchar_t *name, *value;
MSVCRT_wchar_t *dst = name; MSVCRT_wchar_t *dst;
int ret; int ret;
TRACE("%s\n", debugstr_w(str)); TRACE("%s\n", debugstr_w(str));
if (!str) if (!str)
return -1; return -1;
name = HeapAlloc(GetProcessHeap(), 0, (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t));
if (!name)
return -1;
dst = name;
while (*str && *str != '=') while (*str && *str != '=')
*dst++ = *str++; *dst++ = *str++;
if (!*str++) if (!*str++)
return -1; {
*dst = 0; ret = -1;
dst = value; goto finish;
}
*dst++ = 0;
value = dst;
while (*str) while (*str)
*dst++ = *str++; *dst++ = *str++;
*dst = 0; *dst = 0;
@ -137,5 +155,8 @@ int _wputenv(const MSVCRT_wchar_t *str)
_environ = msvcrt_SnapshotOfEnvironmentA(_environ); _environ = msvcrt_SnapshotOfEnvironmentA(_environ);
if (_wenviron) if (_wenviron)
_wenviron = msvcrt_SnapshotOfEnvironmentW(_wenviron); _wenviron = msvcrt_SnapshotOfEnvironmentW(_wenviron);
finish:
HeapFree(GetProcessHeap(), 0, name);
return ret; return ret;
} }

View File

@ -21,6 +21,27 @@
#include "wine/test.h" #include "wine/test.h"
#include <stdlib.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) START_TEST(environ)
{ {
ok( _putenv("cat=") == 0, "_putenv failed on deletion of nonexistent environment variable\n" ); 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("=") == -1, "should not accept '=' as input\n" );
ok( _putenv("=dog") == -1, "should not accept '=dog' 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" ); ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" );
} }