wininet[2/3]: make HttpQueryInfo[AW] work for lpBuffer == NULL and len>0 (with testcase, fixes bug #9006)

Mikolaj Zalewski mikolaj at zalewski.pl
Wed Aug 15 19:02:26 CDT 2007


-------------- next part --------------
>From 409ee5dabcf3e6de79af93cf4521d2698dfd0de5 Mon Sep 17 00:00:00 2001
From: Mikolaj Zalewski <mikolajz at mikolajz.smo.corp.google.com>
Date: Wed, 15 Aug 2007 16:55:15 -0700
Subject: [PATCH] wininet: make HttpQueryInfo[AW] work for lpBuffer == NULL and len>0 (with testcase, fixes bug #9006)
---
 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 aa7a4f4..8d93448 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -1973,6 +1973,8 @@ #undef FE
 	goto lend;
     }
 
+    if (lpBuffer == NULL)
+        *lpdwBufferLength = 0;
     bSuccess = HTTP_HttpQueryInfoW( lpwhr, dwInfoLevel,
 	                            lpBuffer, lpdwBufferLength, lpdwIndex);
 
@@ -2008,11 +2010,19 @@ BOOL WINAPI HttpQueryInfoA(HINTERNET hHt
                                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 00f417d..d16d93d 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);
-- 
1.4.1



More information about the wine-patches mailing list