2022-09-19 15:49:48 -07:00
|
|
|
From ec84f3463bb1750c51e062b80c3ce16dabb972e0 Mon Sep 17 00:00:00 2001
|
2015-05-15 18:43:53 -07:00
|
|
|
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
|
|
|
|
Date: Sat, 16 May 2015 03:16:15 +0200
|
2019-11-25 16:52:26 -08:00
|
|
|
Subject: [PATCH] wininet: Replacing header fields should fail if they do not
|
|
|
|
exist yet.
|
2015-05-15 18:43:53 -07:00
|
|
|
|
|
|
|
A lot of details are not properly covered by tests yet and were
|
|
|
|
marked with FIXME comments. The implementation was written in such
|
|
|
|
a way that it behaves identical to the old code in such situations.
|
|
|
|
---
|
2022-03-04 14:58:02 -08:00
|
|
|
dlls/wininet/http.c | 197 ++++++++++++++++++++++----------------------
|
|
|
|
1 file changed, 99 insertions(+), 98 deletions(-)
|
2015-05-15 18:43:53 -07:00
|
|
|
|
|
|
|
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
|
2022-09-19 15:49:48 -07:00
|
|
|
index 575ebab24c6..132ed61e1de 100644
|
2015-05-15 18:43:53 -07:00
|
|
|
--- a/dlls/wininet/http.c
|
|
|
|
+++ b/dlls/wininet/http.c
|
2022-09-19 15:49:48 -07:00
|
|
|
@@ -6112,130 +6112,131 @@ static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer)
|
2015-05-15 18:43:53 -07:00
|
|
|
|
|
|
|
static DWORD HTTP_ProcessHeader(http_request_t *request, LPCWSTR field, LPCWSTR value, DWORD dwModifier)
|
|
|
|
{
|
|
|
|
- LPHTTPHEADERW lphttpHdr = NULL;
|
2022-02-22 19:27:11 -08:00
|
|
|
+ LPHTTPHEADERW lphttpHdr;
|
2022-03-04 14:58:02 -08:00
|
|
|
INT index;
|
|
|
|
BOOL request_only = !!(dwModifier & HTTP_ADDHDR_FLAG_REQ);
|
|
|
|
- DWORD res = ERROR_HTTP_INVALID_HEADER;
|
2015-05-15 18:43:53 -07:00
|
|
|
+ DWORD res = ERROR_SUCCESS;
|
|
|
|
|
2022-03-04 14:58:02 -08:00
|
|
|
TRACE("--> %s: %s - 0x%08lx\n", debugstr_w(field), debugstr_w(value), dwModifier);
|
2015-05-15 18:43:53 -07:00
|
|
|
|
2022-03-04 14:58:02 -08:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
2015-05-15 18:43:53 -07:00
|
|
|
|
|
|
|
- /* REPLACE wins out over ADD */
|
2022-09-19 15:49:48 -07:00
|
|
|
- if (dwModifier & HTTP_ADDREQ_FLAG_REPLACE)
|
|
|
|
- dwModifier &= ~HTTP_ADDREQ_FLAG_ADD;
|
2015-05-15 18:43:53 -07:00
|
|
|
+ index = HTTP_GetCustomHeaderIndex(request, field, 0, request_only);
|
2022-02-22 19:27:11 -08:00
|
|
|
+ if (index >= 0)
|
|
|
|
+ {
|
|
|
|
+ lphttpHdr = &request->custHeaders[index];
|
|
|
|
|
2022-09-19 15:49:48 -07:00
|
|
|
- if (dwModifier & HTTP_ADDREQ_FLAG_ADD)
|
|
|
|
- index = -1;
|
|
|
|
- else
|
|
|
|
- index = HTTP_GetCustomHeaderIndex(request, field, 0, request_only);
|
|
|
|
-
|
2022-02-22 19:27:11 -08:00
|
|
|
- if (index >= 0)
|
|
|
|
- {
|
2022-09-19 15:49:48 -07:00
|
|
|
- if (dwModifier & HTTP_ADDREQ_FLAG_ADD_IF_NEW)
|
2022-02-22 19:27:11 -08:00
|
|
|
+ /* replace existing header if FLAG_REPLACE is given */
|
2022-09-19 15:49:48 -07:00
|
|
|
+ if (dwModifier & HTTP_ADDREQ_FLAG_REPLACE)
|
2022-02-22 19:27:11 -08:00
|
|
|
{
|
2015-05-15 18:43:53 -07:00
|
|
|
- LeaveCriticalSection( &request->headers_section );
|
|
|
|
- return ERROR_HTTP_INVALID_HEADER;
|
|
|
|
- }
|
2022-02-22 19:27:11 -08:00
|
|
|
- lphttpHdr = &request->custHeaders[index];
|
2015-05-15 18:43:53 -07:00
|
|
|
- }
|
|
|
|
- else if (value)
|
|
|
|
- {
|
|
|
|
- HTTPHEADERW hdr;
|
2022-02-22 19:27:11 -08:00
|
|
|
+ HTTP_DeleteCustomHeader( request, index );
|
2015-05-15 18:43:53 -07:00
|
|
|
|
|
|
|
- hdr.lpszField = (LPWSTR)field;
|
|
|
|
- hdr.lpszValue = (LPWSTR)value;
|
|
|
|
- hdr.wFlags = hdr.wCount = 0;
|
|
|
|
+ if (value && value[0])
|
|
|
|
+ {
|
|
|
|
+ HTTPHEADERW hdr;
|
|
|
|
|
2022-02-22 19:27:11 -08:00
|
|
|
- if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
- hdr.wFlags |= HDR_ISREQUEST;
|
|
|
|
+ hdr.lpszField = (LPWSTR)field;
|
|
|
|
+ hdr.lpszValue = (LPWSTR)value;
|
|
|
|
+ hdr.wFlags = hdr.wCount = 0;
|
|
|
|
|
2015-05-15 18:43:53 -07:00
|
|
|
- res = HTTP_InsertCustomHeader(request, &hdr);
|
|
|
|
- LeaveCriticalSection( &request->headers_section );
|
|
|
|
- return res;
|
|
|
|
- }
|
|
|
|
- /* no value to delete */
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- LeaveCriticalSection( &request->headers_section );
|
|
|
|
- return ERROR_SUCCESS;
|
|
|
|
- }
|
2022-02-22 19:27:11 -08:00
|
|
|
+ if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
+ hdr.wFlags |= HDR_ISREQUEST;
|
2015-05-15 18:43:53 -07:00
|
|
|
|
|
|
|
- if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
- lphttpHdr->wFlags |= HDR_ISREQUEST;
|
|
|
|
- else
|
|
|
|
- lphttpHdr->wFlags &= ~HDR_ISREQUEST;
|
2022-02-22 19:27:11 -08:00
|
|
|
+ res = HTTP_InsertCustomHeader( request, &hdr );
|
|
|
|
+ }
|
2015-05-15 18:43:53 -07:00
|
|
|
|
2022-09-19 15:49:48 -07:00
|
|
|
- if (dwModifier & HTTP_ADDREQ_FLAG_REPLACE)
|
2015-05-15 18:43:53 -07:00
|
|
|
- {
|
|
|
|
- HTTP_DeleteCustomHeader( request, index );
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
2022-09-19 15:49:48 -07:00
|
|
|
|
|
|
|
- if (value && value[0])
|
2015-05-15 18:43:53 -07:00
|
|
|
+ /* do not add new header if FLAG_ADD_IF_NEW is set */
|
2022-09-19 15:49:48 -07:00
|
|
|
+ if (dwModifier & HTTP_ADDREQ_FLAG_ADD_IF_NEW)
|
2022-02-22 19:27:11 -08:00
|
|
|
+ {
|
2015-05-15 18:43:53 -07:00
|
|
|
+ res = ERROR_HTTP_INVALID_HEADER; /* FIXME */
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
2022-09-19 15:49:48 -07:00
|
|
|
+
|
2015-05-15 18:43:53 -07:00
|
|
|
+ /* handle appending to existing header */
|
|
|
|
+ if (dwModifier & COALESCEFLAGS)
|
2022-02-22 19:27:11 -08:00
|
|
|
{
|
|
|
|
- HTTPHEADERW hdr;
|
2015-05-15 18:43:53 -07:00
|
|
|
+ LPWSTR lpsztmp;
|
|
|
|
+ WCHAR ch = 0;
|
|
|
|
+ INT len = 0;
|
2019-11-25 16:52:26 -08:00
|
|
|
+ INT origlen = lstrlenW(lphttpHdr->lpszValue);
|
|
|
|
+ INT valuelen = lstrlenW(value);
|
2022-02-22 19:27:11 -08:00
|
|
|
+
|
2015-05-15 18:43:53 -07:00
|
|
|
+ /* FIXME: Should it really clear HDR_ISREQUEST? */
|
2022-02-22 19:27:11 -08:00
|
|
|
+ if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
2015-05-15 18:43:53 -07:00
|
|
|
+ lphttpHdr->wFlags |= HDR_ISREQUEST;
|
|
|
|
+ else
|
|
|
|
+ lphttpHdr->wFlags &= ~HDR_ISREQUEST;
|
2022-03-04 14:58:02 -08:00
|
|
|
|
|
|
|
- hdr.lpszField = (LPWSTR)field;
|
|
|
|
- hdr.lpszValue = (LPWSTR)value;
|
|
|
|
- hdr.wFlags = hdr.wCount = 0;
|
2022-09-19 15:49:48 -07:00
|
|
|
+ if (dwModifier & HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA)
|
2015-05-15 18:43:53 -07:00
|
|
|
+ {
|
|
|
|
+ ch = ',';
|
|
|
|
+ lphttpHdr->wFlags |= HDR_COMMADELIMITED;
|
|
|
|
+ }
|
2022-09-19 15:49:48 -07:00
|
|
|
+ else if (dwModifier & HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON)
|
2015-05-15 18:43:53 -07:00
|
|
|
+ {
|
|
|
|
+ ch = ';';
|
|
|
|
+ lphttpHdr->wFlags |= HDR_COMMADELIMITED;
|
|
|
|
+ }
|
|
|
|
|
2022-02-22 19:27:11 -08:00
|
|
|
- if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
- hdr.wFlags |= HDR_ISREQUEST;
|
2022-03-04 14:58:02 -08:00
|
|
|
+ len = origlen + valuelen + ((ch > 0) ? 2 : 0);
|
|
|
|
|
|
|
|
- res = HTTP_InsertCustomHeader(request, &hdr);
|
|
|
|
- LeaveCriticalSection( &request->headers_section );
|
|
|
|
- return res;
|
|
|
|
- }
|
2015-05-15 18:43:53 -07:00
|
|
|
+ lpsztmp = heap_realloc(lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR));
|
|
|
|
+ if (lpsztmp)
|
|
|
|
+ {
|
|
|
|
+ lphttpHdr->lpszValue = lpsztmp;
|
|
|
|
+ /* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */
|
|
|
|
+ if (ch > 0)
|
|
|
|
+ {
|
|
|
|
+ lphttpHdr->lpszValue[origlen] = ch;
|
|
|
|
+ origlen++;
|
|
|
|
+ lphttpHdr->lpszValue[origlen] = ' ';
|
|
|
|
+ origlen++;
|
|
|
|
+ }
|
|
|
|
|
2022-03-04 14:58:02 -08:00
|
|
|
- LeaveCriticalSection( &request->headers_section );
|
|
|
|
- return ERROR_SUCCESS;
|
|
|
|
- }
|
|
|
|
- else if (dwModifier & COALESCEFLAGS)
|
2015-05-15 18:43:53 -07:00
|
|
|
+ memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR));
|
|
|
|
+ lphttpHdr->lpszValue[len] = '\0';
|
|
|
|
+ }
|
|
|
|
+ else
|
2022-02-22 19:27:11 -08:00
|
|
|
+ {
|
2015-05-15 18:43:53 -07:00
|
|
|
+ WARN("heap_realloc (%d bytes) failed\n",len+1);
|
|
|
|
+ res = ERROR_OUTOFMEMORY;
|
2022-02-22 19:27:11 -08:00
|
|
|
+ }
|
2022-03-04 14:58:02 -08:00
|
|
|
+
|
2015-05-15 18:43:53 -07:00
|
|
|
+ goto out;
|
2022-02-22 19:27:11 -08:00
|
|
|
+ }
|
|
|
|
+ }
|
2015-05-15 18:43:53 -07:00
|
|
|
+
|
|
|
|
+ /* FIXME: What about other combinations? */
|
2022-09-19 15:49:48 -07:00
|
|
|
+ if ((dwModifier & ~HTTP_ADDHDR_FLAG_REQ) == HTTP_ADDREQ_FLAG_REPLACE)
|
2022-02-22 19:27:11 -08:00
|
|
|
{
|
|
|
|
- LPWSTR lpsztmp;
|
|
|
|
- WCHAR ch = 0;
|
|
|
|
- INT len = 0;
|
|
|
|
- INT origlen = lstrlenW(lphttpHdr->lpszValue);
|
|
|
|
- INT valuelen = lstrlenW(value);
|
2015-05-15 18:43:53 -07:00
|
|
|
+ res = ERROR_HTTP_HEADER_NOT_FOUND;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
2022-02-22 19:27:11 -08:00
|
|
|
|
2022-09-19 15:49:48 -07:00
|
|
|
- if (dwModifier & HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA)
|
2022-02-22 19:27:11 -08:00
|
|
|
- {
|
|
|
|
- ch = ',';
|
|
|
|
- lphttpHdr->wFlags |= HDR_COMMADELIMITED;
|
|
|
|
- }
|
2022-09-19 15:49:48 -07:00
|
|
|
- else if (dwModifier & HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON)
|
2022-02-22 19:27:11 -08:00
|
|
|
- {
|
|
|
|
- ch = ';';
|
|
|
|
- lphttpHdr->wFlags |= HDR_COMMADELIMITED;
|
|
|
|
- }
|
2015-05-15 18:43:53 -07:00
|
|
|
+ /* FIXME: What if value == ""? */
|
|
|
|
+ if (value)
|
|
|
|
+ {
|
|
|
|
+ HTTPHEADERW hdr;
|
2022-02-22 19:27:11 -08:00
|
|
|
|
|
|
|
- len = origlen + valuelen + ((ch > 0) ? 2 : 0);
|
2015-05-15 18:43:53 -07:00
|
|
|
+ hdr.lpszField = (LPWSTR)field;
|
|
|
|
+ hdr.lpszValue = (LPWSTR)value;
|
|
|
|
+ hdr.wFlags = hdr.wCount = 0;
|
2022-02-22 19:27:11 -08:00
|
|
|
|
|
|
|
- lpsztmp = heap_realloc(lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR));
|
|
|
|
- if (lpsztmp)
|
|
|
|
- {
|
|
|
|
- lphttpHdr->lpszValue = lpsztmp;
|
|
|
|
- /* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */
|
|
|
|
- if (ch > 0)
|
|
|
|
- {
|
|
|
|
- lphttpHdr->lpszValue[origlen] = ch;
|
|
|
|
- origlen++;
|
|
|
|
- lphttpHdr->lpszValue[origlen] = ' ';
|
|
|
|
- origlen++;
|
|
|
|
- }
|
2015-05-15 18:43:53 -07:00
|
|
|
+ if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
+ hdr.wFlags |= HDR_ISREQUEST;
|
2022-02-22 19:27:11 -08:00
|
|
|
|
|
|
|
- memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR));
|
|
|
|
- lphttpHdr->lpszValue[len] = '\0';
|
|
|
|
- res = ERROR_SUCCESS;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- WARN("heap_realloc (%d bytes) failed\n",len+1);
|
|
|
|
- res = ERROR_OUTOFMEMORY;
|
|
|
|
- }
|
2015-05-15 18:43:53 -07:00
|
|
|
+ res = HTTP_InsertCustomHeader( request, &hdr );
|
|
|
|
+ goto out;
|
2022-02-22 19:27:11 -08:00
|
|
|
}
|
|
|
|
- TRACE("<-- %ld\n", res);
|
|
|
|
- LeaveCriticalSection( &request->headers_section );
|
|
|
|
- return res;
|
2015-05-15 18:43:53 -07:00
|
|
|
+
|
|
|
|
+ /* FIXME: What if value == NULL? */
|
|
|
|
+out:
|
2022-02-22 19:27:11 -08:00
|
|
|
+ TRACE("<-- %ld\n", res);
|
|
|
|
+ LeaveCriticalSection( &request->headers_section );
|
|
|
|
+ return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2015-05-15 18:43:53 -07:00
|
|
|
--
|
2022-09-19 15:49:48 -07:00
|
|
|
2.35.1
|
2015-05-15 18:43:53 -07:00
|
|
|
|