Commit f877fe9b authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wininet: Properly handle output buffer size in InternetGetCookieA.

parent 0c02e358
...@@ -678,7 +678,7 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName, ...@@ -678,7 +678,7 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
LPSTR lpCookieData, LPDWORD lpdwSize) LPSTR lpCookieData, LPDWORD lpdwSize)
{ {
WCHAR *url, *name; WCHAR *url, *name;
DWORD len; DWORD len, size;
BOOL r; BOOL r;
TRACE("(%s %s %p %p(%u))\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName), TRACE("(%s %s %p %p(%u))\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName),
...@@ -701,8 +701,18 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName, ...@@ -701,8 +701,18 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
{ {
r = InternetGetCookieW( url, name, szCookieData, &len ); r = InternetGetCookieW( url, name, szCookieData, &len );
*lpdwSize = WideCharToMultiByte( CP_ACP, 0, szCookieData, len, if(r) {
lpCookieData, lpCookieData ? *lpdwSize : 0, NULL, NULL ); 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 ); heap_free( szCookieData );
} }
......
...@@ -414,6 +414,13 @@ static void test_complicated_cookie(void) ...@@ -414,6 +414,13 @@ static void test_complicated_cookie(void)
ok(strstr(buffer,"M=N")==NULL,"M=N present\n"); ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
ok(strstr(buffer,"O=P")==NULL,"O=P 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; len = 1024;
ret = InternetGetCookieW(testing_example_comW, NULL, NULL, &len); ret = InternetGetCookieW(testing_example_comW, NULL, NULL, &len);
ok(ret == TRUE,"InternetGetCookieW failed\n"); ok(ret == TRUE,"InternetGetCookieW failed\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