wininet: Fixed NULL cookie data pointer handling in InternetGetCookieA.

This commit is contained in:
Jacek Caban 2012-12-03 15:01:08 +01:00 committed by Alexandre Julliard
parent ed42609f54
commit 21e7e28d64
2 changed files with 39 additions and 5 deletions

View File

@ -657,12 +657,12 @@ BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
LPSTR lpCookieData, LPDWORD lpdwSize)
{
WCHAR *url, *name;
DWORD len;
LPWSTR szCookieData = NULL, url, name;
BOOL r;
TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName),
lpCookieData);
TRACE("(%s %s %p %p(%u))\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName),
lpCookieData, lpdwSize, lpdwSize ? *lpdwSize : 0);
url = heap_strdupAtoW(lpszUrl);
name = heap_strdupAtoW(lpszCookieName);
@ -670,6 +670,8 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
r = InternetGetCookieW( url, name, NULL, &len );
if( r )
{
WCHAR *szCookieData;
szCookieData = heap_alloc(len * sizeof(WCHAR));
if( !szCookieData )
{
@ -680,10 +682,11 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
r = InternetGetCookieW( url, name, szCookieData, &len );
*lpdwSize = WideCharToMultiByte( CP_ACP, 0, szCookieData, len,
lpCookieData, *lpdwSize, NULL, NULL );
lpCookieData, lpCookieData ? *lpdwSize : 0, NULL, NULL );
heap_free( szCookieData );
}
}
heap_free( szCookieData );
heap_free( name );
heap_free( url );
return r;

View File

@ -370,6 +370,10 @@ static void test_complicated_cookie(void)
CHAR buffer[1024];
CHAR user[256];
WCHAR wbuf[1024];
static const WCHAR testing_example_comW[] =
{'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.','e','x','a','m','p','l','e','.','c','o','m',0};
ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
ok(ret == TRUE,"InternetSetCookie failed\n");
@ -391,8 +395,16 @@ static void test_complicated_cookie(void)
ok(ret == TRUE,"InternetSetCookie failed\n");
len = 1024;
ret = InternetGetCookie("http://testing.example.com", NULL, NULL, &len);
ok(ret == TRUE,"InternetGetCookie failed\n");
ok(len == 19, "len = %u\n", len);
len = 1024;
memset(buffer, 0xac, sizeof(buffer));
ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
ok(ret == TRUE,"InternetGetCookie failed\n");
ok(len == 19, "len = %u\n", len);
ok(strlen(buffer) == 18, "strlen(buffer) = %u\n", lstrlenA(buffer));
ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
@ -402,6 +414,18 @@ 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 = 1024;
ret = InternetGetCookieW(testing_example_comW, NULL, NULL, &len);
ok(ret == TRUE,"InternetGetCookieW failed\n");
ok(len == 38, "len = %u\n", len);
len = 1024;
memset(wbuf, 0xac, sizeof(wbuf));
ret = InternetGetCookieW(testing_example_comW, NULL, wbuf, &len);
ok(ret == TRUE,"InternetGetCookieW failed\n");
ok(len == 19, "len = %u\n", len);
ok(lstrlenW(wbuf) == 18, "strlenW(wbuf) = %u\n", lstrlenW(wbuf));
len = 1024;
ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
ok(ret == TRUE,"InternetGetCookie failed\n");
@ -465,6 +489,7 @@ static void test_complicated_cookie(void)
len = 1024;
ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
ok(ret == TRUE,"InternetGetCookie failed\n");
ok(len == 24, "len = %u\n", 24);
ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
@ -474,6 +499,12 @@ 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");
/* Cookie name argument is not implemented */
len = 1024;
ret = InternetGetCookie("http://testing.example.com/bar/foo", "A", buffer, &len);
ok(ret == TRUE,"InternetGetCookie failed\n");
ok(len == 24, "len = %u\n", 24);
/* test persistent cookies */
ret = InternetSetCookie("http://testing.example.com", NULL, "A=B; expires=Fri, 01-Jan-2038 00:00:00 GMT");
ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());