wininet: Properly handle output buffer size in InternetGetCookieA.

This commit is contained in:
Jacek Caban 2012-12-27 17:54:29 +01:00 committed by Alexandre Julliard
parent 0c02e35841
commit f877fe9ba4
2 changed files with 20 additions and 3 deletions

View File

@ -678,7 +678,7 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
LPSTR lpCookieData, LPDWORD lpdwSize)
{
WCHAR *url, *name;
DWORD len;
DWORD len, size;
BOOL r;
TRACE("(%s %s %p %p(%u))\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName),
@ -701,8 +701,18 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
{
r = InternetGetCookieW( url, name, szCookieData, &len );
*lpdwSize = WideCharToMultiByte( CP_ACP, 0, szCookieData, len,
lpCookieData, lpCookieData ? *lpdwSize : 0, NULL, NULL );
if(r) {
size = WideCharToMultiByte( CP_ACP, 0, szCookieData, len, NULL, 0, NULL, NULL);
if(lpCookieData) {
if(*lpdwSize >= size) {
WideCharToMultiByte( CP_ACP, 0, szCookieData, len, lpCookieData, *lpdwSize, NULL, NULL);
}else {
SetLastError(ERROR_INSUFFICIENT_BUFFER);
r = FALSE;
}
}
*lpdwSize = size;
}
heap_free( szCookieData );
}

View File

@ -414,6 +414,13 @@ static void test_complicated_cookie(void)
ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
len = 10;
memset(buffer, 0xac, sizeof(buffer));
ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"InternetGetCookie returned: %x(%u), expected ERROR_INSUFFICIENT_BUFFER\n", ret, GetLastError());
ok(len == 19, "len = %u\n", len);
len = 1024;
ret = InternetGetCookieW(testing_example_comW, NULL, NULL, &len);
ok(ret == TRUE,"InternetGetCookieW failed\n");