In HttpSendRequestW and HttpSendRequestExW, if the header pointer is not null but the length parameter is 0, the header length should be derived from the string length instead.
In HttpSendRequestA and HttpSendRequestExA, on the same scenario, the function should fail instead.
-- v2: wininet: Handle http headers correctly when length is 0
From: Hans Lehnert hans.lehnert@gmail.com
In HttpSendRequestW and HttpSendRequestExW, if the header pointer is not null but the length parameter is 0, the header length should be derived from the string length instead.
In HttpSendRequestA and HttpSendRequestExA, on the same scenario, the function should fail instead. --- dlls/wininet/http.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index b646ddf5b69..ac3a1955270 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -1274,7 +1274,7 @@ BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
TRACE("%p, %s, %lu, %08lx\n", hHttpRequest, debugstr_wn(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier);
- if (!lpszHeader) + if (!lpszHeader) return TRUE;
request = (http_request_t*) get_handle_object( hHttpRequest ); @@ -4063,13 +4063,13 @@ BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel, info_mod &= ~ modifier_flags[i].val; } } - + if (info_mod) { TRACE(" Unknown (%08lx)", info_mod); } TRACE("\n"); } - + request = (http_request_t*) get_handle_object( hHttpRequest ); if (NULL == request || request->hdr.htype != WH_HHTTPREQ) { @@ -5043,8 +5043,13 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, }
/* add the headers the caller supplied */ - if( lpszHeaders && dwHeaderLength ) + if (lpszHeaders) + { + if (dwHeaderLength == 0) + dwHeaderLength = lstrlenW(lpszHeaders); + HTTP_HttpAddRequestHeadersW(request, lpszHeaders, dwHeaderLength, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE); + }
do { @@ -5551,6 +5556,12 @@ BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest, BuffersInW.dwStructSize = sizeof(LPINTERNET_BUFFERSW); if (lpBuffersIn->lpcszHeader) { + if (lpBuffersIn->dwHeadersLength == 0 && *lpBuffersIn->lpcszHeader != '\0') + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + headerlen = MultiByteToWideChar(CP_ACP,0,lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength,0,0); header = malloc(headerlen * sizeof(WCHAR)); @@ -5773,6 +5784,12 @@ BOOL WINAPI HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders, DWORD nLen=dwHeaderLength; if(lpszHeaders!=NULL) { + if (dwHeaderLength == 0 && *lpszHeaders != '\0') + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + nLen=MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,NULL,0); szHeaders = malloc(nLen * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,szHeaders,nLen);