Commit 35a9398f authored by qingdoa daoo's avatar qingdoa daoo Committed by Alexandre Julliard

msvcrt: Allow environment strings longer than 512 characters.

parent 6a13925a
......@@ -73,20 +73,28 @@ MSVCRT_wchar_t *_wgetenv(const MSVCRT_wchar_t *name)
*/
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;
}
......@@ -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" );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment