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

This commit is contained in:
Robert Reif 2006-08-19 13:27:01 -04:00 committed by Alexandre Julliard
parent ca80c55ae8
commit 63d4bb7bae
2 changed files with 11 additions and 1 deletions

View File

@ -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;

View File

@ -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));