Rob Shearman : wininet: Fix crash when calling HttpQueryInfoA/W( HTTP_QUERY_RAW_HEADERS) before any response has been received from a server .

Alexandre Julliard julliard at winehq.org
Wed Oct 8 08:32:33 CDT 2008


Module: wine
Branch: master
Commit: 0715d9c12303714e8b98974aa85f479d1f3e1ab0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0715d9c12303714e8b98974aa85f479d1f3e1ab0

Author: Rob Shearman <robertshearman at gmail.com>
Date:   Tue Oct  7 15:39:50 2008 +0100

wininet: Fix crash when calling HttpQueryInfoA/W(HTTP_QUERY_RAW_HEADERS) before any response has been received from a server.

---

 dlls/wininet/http.c       |   31 ++++++++++++++++++-------------
 dlls/wininet/tests/http.c |    6 ++++++
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 3675c9d..f72082b 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -143,21 +143,26 @@ static LPWSTR * HTTP_Tokenize(LPCWSTR string, LPCWSTR token_string)
     int i;
     LPCWSTR next_token;
 
-    /* empty string has no tokens */
-    if (*string)
-        tokens++;
-    /* count tokens */
-    for (i = 0; string[i]; i++)
-        if (!strncmpW(string+i, token_string, strlenW(token_string)))
-        {
-            DWORD j;
+    if (string)
+    {
+        /* empty string has no tokens */
+        if (*string)
             tokens++;
-            /* we want to skip over separators, but not the null terminator */
-            for (j = 0; j < strlenW(token_string) - 1; j++)
-                if (!string[i+j])
-                    break;
-            i += j;
+        /* count tokens */
+        for (i = 0; string[i]; i++)
+        {
+            if (!strncmpW(string+i, token_string, strlenW(token_string)))
+            {
+                DWORD j;
+                tokens++;
+                /* we want to skip over separators, but not the null terminator */
+                for (j = 0; j < strlenW(token_string) - 1; j++)
+                    if (!string[i+j])
+                        break;
+                i += j;
+            }
         }
+    }
 
     /* add 1 for terminating NULL */
     token_array = HeapAlloc(GetProcessHeap(), 0, (tokens+1) * sizeof(*token_array));
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c
index 3a1a13f..93752bd 100644
--- a/dlls/wininet/tests/http.c
+++ b/dlls/wininet/tests/http.c
@@ -296,6 +296,12 @@ static void InternetReadFile_test(int flags)
     ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
     ok(!strcmp(buffer, "http://www.winehq.org/about/"), "Wrong URL %s\n", buffer);
 
+    length = sizeof(buffer);
+    res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0);
+    ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
+    ok(length == 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
+    ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
+
     CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
     CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
     CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);




More information about the wine-cvs mailing list