Juan Lang : wininet: Correct user agent handling.
Alexandre Julliard
julliard at winehq.org
Mon Oct 5 09:54:22 CDT 2009
Module: wine
Branch: master
Commit: 05a7e3d38653660abed38604b7df9225bf26b54b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=05a7e3d38653660abed38604b7df9225bf26b54b
Author: Juan Lang <juan.lang at gmail.com>
Date: Fri Oct 2 08:31:31 2009 -0700
wininet: Correct user agent handling.
---
dlls/wininet/internet.c | 27 +++++++++++++++++++++++----
dlls/wininet/tests/internet.c | 4 ++--
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index 619674e..bad49e4 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -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;
diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c
index 144c630..622711a 100644
--- a/dlls/wininet/tests/internet.c
+++ b/dlls/wininet/tests/internet.c
@@ -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);
More information about the wine-cvs
mailing list