From 0715d9c12303714e8b98974aa85f479d1f3e1ab0 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Tue, 7 Oct 2008 15:39:50 +0100 Subject: [PATCH] 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 3675c9d9a32..f72082b3035 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 3a1a13f528e..93752bd1e91 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);