Commit 63d4bb7b authored by Robert Reif's avatar Robert Reif Committed by Alexandre Julliard

kernel32: Fix ExpandEnvironmentStrings to not overflow UNICODE_STRING buffer size (with test).

parent ca80c55a
......@@ -345,6 +345,11 @@ DWORD WINAPI ExpandEnvironmentStringsW( LPCWSTR src, LPWSTR dst, DWORD len )
TRACE("(%s %p %lu)\n", debugstr_w(src), dst, len);
RtlInitUnicodeString(&us_src, src);
/* make sure we don't overflow maximum UNICODE_STRING size */
if (len > 0x7fff)
len = 0x7fff;
us_dst.Length = 0;
us_dst.MaximumLength = len * sizeof(WCHAR);
us_dst.Buffer = dst;
......
......@@ -213,9 +213,14 @@ static void test_GetSetEnvironmentVariableW(void)
static void test_ExpandEnvironmentStringsA(void)
{
char buf[256], buf1[256];
char buf[256], buf1[256], buf2[0x8000];
DWORD ret_size, ret_size1;
/* test a large destination size */
strcpy(buf, "12345");
ret_size = ExpandEnvironmentStringsA(buf, buf2, sizeof(buf2));
ok(!strcmp(buf, buf2), "ExpandEnvironmentStrings failed %s vs %s. ret_size = %ld\n", buf, buf2, ret_size);
ret_size1 = GetWindowsDirectoryA(buf1,256);
ok ((ret_size1 >0) && (ret_size1<256), "GetWindowsDirectory Failed\n");
ret_size = ExpandEnvironmentStringsA("%SystemRoot%",buf,sizeof(buf));
......
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