From bc9e214f6fb2ea68c9fcd7f635c47f3e85fc695c Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 27 Aug 2008 16:54:17 -0700 Subject: [PATCH] wininet: Work around NULL headers when handling HTTP_QUERY_RAW_HEADERS_CRLF. --- dlls/wininet/http.c | 15 ++++++++++++--- dlls/wininet/tests/http.c | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 4630f3bac9d..b8ecb47b749 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -2187,15 +2187,18 @@ static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD dwInfoLev case HTTP_QUERY_RAW_HEADERS_CRLF: { LPWSTR headers; - DWORD len; + DWORD len = 0; BOOL ret = FALSE; + static const WCHAR CRLF[] = {'\r','\n',0}; if (request_only) headers = HTTP_BuildHeaderRequestString(lpwhr, lpwhr->lpszVerb, lpwhr->lpszPath, lpwhr->lpszVersion); else headers = lpwhr->lpszRawHeaders; - len = strlenW(headers) * sizeof(WCHAR); + if (headers) + len = strlenW(headers) * sizeof(WCHAR); + if (len + sizeof(WCHAR) > *lpdwBufferLength) { len += sizeof(WCHAR); @@ -2204,7 +2207,13 @@ static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD dwInfoLev } else if (lpBuffer) { - memcpy(lpBuffer, headers, len + sizeof(WCHAR)); + if (headers) + memcpy(lpBuffer, headers, len + sizeof(WCHAR)); + else + { + len = strlenW(CRLF) * sizeof(WCHAR); + memcpy(lpBuffer, CRLF, sizeof(CRLF)); + } TRACE("returning data: %s\n", debugstr_wn(lpBuffer, len / sizeof(WCHAR))); ret = TRUE; } diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 9ad6274f465..1c52f270499 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -1208,6 +1208,16 @@ static void HttpHeaders_test(void) /* end of W version tests */ + /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */ + index = 0; + len = sizeof(buffer); + memset(buffer, 'x', sizeof(buffer)); + ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF, + buffer,&len,&index) == TRUE,"Query failed\n"); + ok(len == 2, "Expected 2, got %d\n", len); + ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer); + ok(index == 0, "Index was incremented\n"); + ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD), "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");