Module: wine Branch: master Commit: 694a09284a8e5e3fa3782d7be5ab13074c0a6201 URL: http://source.winehq.org/git/wine.git/?a=commit;h=694a09284a8e5e3fa3782d7be5...
Author: Hans Leidekker hans@it.vu.nl Date: Sun May 18 21:09:50 2008 +0200
wininet: Fix buffer size query for HttpQueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF).
---
dlls/wininet/http.c | 17 ++++++++--------- dlls/wininet/tests/http.c | 7 ++++++- 2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 24918fc..a70bcff 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -2197,27 +2197,26 @@ static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD dwInfoLev { LPWSTR headers; DWORD len; - BOOL ret; + BOOL ret = FALSE;
if (request_only) headers = HTTP_BuildHeaderRequestString(lpwhr, lpwhr->lpszVerb, lpwhr->lpszPath, lpwhr->lpszVersion); else headers = lpwhr->lpszRawHeaders;
- len = strlenW(headers); - if (len + 1 > *lpdwBufferLength/sizeof(WCHAR)) + len = (strlenW(headers) + 1) * sizeof(WCHAR); + if (len > *lpdwBufferLength) { - *lpdwBufferLength = (len + 1) * sizeof(WCHAR); INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); ret = FALSE; - } else + } + else if (lpBuffer) { - memcpy(lpBuffer, headers, (len+1)*sizeof(WCHAR)); - *lpdwBufferLength = len * sizeof(WCHAR); - - TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len)); + memcpy(lpBuffer, headers, len); + TRACE("returning data: %s\n", debugstr_wn(lpBuffer, len / sizeof(WCHAR))); ret = TRUE; } + *lpdwBufferLength = len;
if (request_only) HeapFree(GetProcessHeap(), 0, headers); diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index b946d3b..1cb9793 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -1848,10 +1848,15 @@ static void test_open_url_async(void) type = 0; size = sizeof(type); ret = InternetQueryOption(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size); - ok(ret, "HttpQueryInfo failed: %u\n", GetLastError()); + ok(ret, "InternetQueryOption failed: %u\n", GetLastError()); ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST, "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
+ size = 0; + ret = HttpQueryInfo(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL); + ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n"); + ok(size > 0, "expected size > 0\n"); + CloseHandle(ctx.event); InternetCloseHandle(ctx.req); InternetCloseHandle(ses);