From 3fa49f0f0273345cbe030ab8a45de5176e153007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Zalewski?= Date: Wed, 15 Aug 2007 16:55:15 -0700 Subject: [PATCH] wininet: Make HttpQueryInfo[AW] work for lpBuffer == NULL and len > 0. --- dlls/wininet/http.c | 20 +++++++++++++++----- dlls/wininet/tests/http.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 50fbf5a3717..9ddd8855f74 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -1973,6 +1973,8 @@ BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel, goto lend; } + if (lpBuffer == NULL) + *lpdwBufferLength = 0; bSuccess = HTTP_HttpQueryInfoW( lpwhr, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex); @@ -2008,11 +2010,19 @@ BOOL WINAPI HttpQueryInfoA(HINTERNET hHttpRequest, DWORD dwInfoLevel, lpdwBufferLength, lpdwIndex ); } - len = (*lpdwBufferLength)*sizeof(WCHAR); - bufferW = HeapAlloc( GetProcessHeap(), 0, len ); - /* buffer is in/out because of HTTP_QUERY_CUSTOM */ - if ((dwInfoLevel & HTTP_QUERY_HEADER_MASK) == HTTP_QUERY_CUSTOM) - MultiByteToWideChar(CP_ACP,0,lpBuffer,-1,bufferW,len); + if (lpBuffer) + { + len = (*lpdwBufferLength)*sizeof(WCHAR); + bufferW = HeapAlloc( GetProcessHeap(), 0, len ); + /* buffer is in/out because of HTTP_QUERY_CUSTOM */ + if ((dwInfoLevel & HTTP_QUERY_HEADER_MASK) == HTTP_QUERY_CUSTOM) + MultiByteToWideChar(CP_ACP,0,lpBuffer,-1,bufferW,len); + } else + { + bufferW = NULL; + len = 0; + } + result = HttpQueryInfoW( hHttpRequest, dwInfoLevel, bufferW, &len, lpdwIndex ); if( result ) diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 00f417d1f46..d16d93d6ced 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -990,6 +990,37 @@ static void HttpHeaders_test(void) ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Second Index Should Not Exist\n"); + + /* a call with NULL will fail but will return the length */ + index = 0; + len = sizeof(buffer); + SetLastError(0xdeadbeef); + ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, + NULL,&len,&index) == FALSE,"Query worked\n"); + ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); + ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len); + ok(index == 0, "Index was incremented\n"); + + /* even for a len that is too small */ + index = 0; + len = 15; + SetLastError(0xdeadbeef); + ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, + NULL,&len,&index) == FALSE,"Query worked\n"); + ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); + ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len); + ok(index == 0, "Index was incremented\n"); + + index = 0; + len = 0; + SetLastError(0xdeadbeef); + ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, + NULL,&len,&index) == FALSE,"Query worked\n"); + ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); + ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len); + ok(index == 0, "Index was incremented\n"); + + /* a working query */ index = 0; len = sizeof(buffer);