wininet: Correct user agent handling.

This commit is contained in:
Juan Lang 2009-10-02 08:31:31 -07:00 committed by Alexandre Julliard
parent b63c1cb219
commit 05a7e3d386
2 changed files with 25 additions and 6 deletions

View File

@ -526,17 +526,36 @@ static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffe
bufsize = *size;
if (unicode) {
*size = (strlenW(ai->lpszAgent) + 1) * sizeof(WCHAR);
DWORD len = ai->lpszAgent ? strlenW(ai->lpszAgent) : 0;
*size = (len + 1) * sizeof(WCHAR);
if(!buffer || bufsize < *size)
return ERROR_INSUFFICIENT_BUFFER;
strcpyW(buffer, ai->lpszAgent);
if (ai->lpszAgent)
strcpyW(buffer, ai->lpszAgent);
else
*(WCHAR *)buffer = 0;
/* If the buffer is copied, the returned length doesn't include
* the NULL terminator.
*/
*size = len * sizeof(WCHAR);
}else {
*size = WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, NULL, 0, NULL, NULL);
if (ai->lpszAgent)
*size = WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, NULL, 0, NULL, NULL);
else
*size = 1;
if(!buffer || bufsize < *size)
return ERROR_INSUFFICIENT_BUFFER;
WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, buffer, *size, NULL, NULL);
if (ai->lpszAgent)
WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, buffer, *size, NULL, NULL);
else
*(char *)buffer = 0;
/* If the buffer is copied, the returned length doesn't include
* the NULL terminator.
*/
*size -= 1;
}
return ERROR_SUCCESS;

View File

@ -184,7 +184,7 @@ static void test_InternetQueryOptionA(void)
if (retval)
{
ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
}
ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
HeapFree(GetProcessHeap(),0,buffer);
@ -231,7 +231,7 @@ static void test_InternetQueryOptionA(void)
len=0;
retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
err=GetLastError();
todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
ok(retval == 0,"Got wrong return value %d\n",retval);
ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);