Commit 24e42651 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

winhttp: Move common code to the upper level, avoid accessing the buffer before…

winhttp: Move common code to the upper level, avoid accessing the buffer before the buffer size check, make the code conform to existing rules.
parent b4e6aa64
...@@ -85,12 +85,6 @@ static void session_destroy( object_header_t *hdr ) ...@@ -85,12 +85,6 @@ static void session_destroy( object_header_t *hdr )
static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen ) static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
{ {
if (!buflen)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
switch (option) switch (option)
{ {
case WINHTTP_OPTION_REDIRECT_POLICY: case WINHTTP_OPTION_REDIRECT_POLICY:
...@@ -98,7 +92,7 @@ static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buf ...@@ -98,7 +92,7 @@ static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buf
if (!buffer || *buflen < sizeof(DWORD)) if (!buffer || *buflen < sizeof(DWORD))
{ {
*buflen = sizeof(DWORD); *buflen = sizeof(DWORD);
SetLastError(ERROR_INSUFFICIENT_BUFFER); set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE; return FALSE;
} }
...@@ -108,19 +102,13 @@ static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buf ...@@ -108,19 +102,13 @@ static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buf
} }
default: default:
FIXME("unimplemented option %u\n", option); FIXME("unimplemented option %u\n", option);
SetLastError(ERROR_INVALID_PARAMETER); set_last_error( ERROR_INVALID_PARAMETER );
return FALSE; return FALSE;
} }
} }
static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen ) static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
{ {
if (!buffer)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
switch (option) switch (option)
{ {
case WINHTTP_OPTION_PROXY: case WINHTTP_OPTION_PROXY:
...@@ -136,7 +124,7 @@ static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffe ...@@ -136,7 +124,7 @@ static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffe
if (buflen != sizeof(policy)) if (buflen != sizeof(policy))
{ {
SetLastError(ERROR_INSUFFICIENT_BUFFER); set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE; return FALSE;
} }
...@@ -146,11 +134,11 @@ static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffe ...@@ -146,11 +134,11 @@ static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffe
return TRUE; return TRUE;
} }
case WINHTTP_OPTION_DISABLE_FEATURE: case WINHTTP_OPTION_DISABLE_FEATURE:
SetLastError(ERROR_WINHTTP_INCORRECT_HANDLE_TYPE); set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
return FALSE; return FALSE;
default: default:
FIXME("unimplemented option %u\n", option); FIXME("unimplemented option %u\n", option);
SetLastError(ERROR_INVALID_PARAMETER); set_last_error( ERROR_INVALID_PARAMETER );
return FALSE; return FALSE;
} }
} }
...@@ -310,12 +298,6 @@ static void request_destroy( object_header_t *hdr ) ...@@ -310,12 +298,6 @@ static void request_destroy( object_header_t *hdr )
static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen ) static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
{ {
if (!buflen)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
switch (option) switch (option)
{ {
case WINHTTP_OPTION_SECURITY_FLAGS: case WINHTTP_OPTION_SECURITY_FLAGS:
...@@ -325,7 +307,7 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf ...@@ -325,7 +307,7 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf
if (!buffer || *buflen < sizeof(flags)) if (!buffer || *buflen < sizeof(flags))
{ {
*buflen = sizeof(flags); *buflen = sizeof(flags);
SetLastError(ERROR_INSUFFICIENT_BUFFER); set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE; return FALSE;
} }
...@@ -343,7 +325,7 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf ...@@ -343,7 +325,7 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf
if (!buffer || *buflen < sizeof(cert)) if (!buffer || *buflen < sizeof(cert))
{ {
*buflen = sizeof(cert); *buflen = sizeof(cert);
SetLastError(ERROR_INSUFFICIENT_BUFFER); set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE; return FALSE;
} }
...@@ -357,7 +339,7 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf ...@@ -357,7 +339,7 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf
if (!buffer || *buflen < sizeof(DWORD)) if (!buffer || *buflen < sizeof(DWORD))
{ {
*buflen = sizeof(DWORD); *buflen = sizeof(DWORD);
SetLastError(ERROR_INSUFFICIENT_BUFFER); set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE; return FALSE;
} }
...@@ -367,19 +349,13 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf ...@@ -367,19 +349,13 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf
} }
default: default:
FIXME("unimplemented option %u\n", option); FIXME("unimplemented option %u\n", option);
SetLastError(ERROR_INVALID_PARAMETER); set_last_error( ERROR_INVALID_PARAMETER );
return FALSE; return FALSE;
} }
} }
static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen ) static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
{ {
if (!buffer)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
switch (option) switch (option)
{ {
case WINHTTP_OPTION_PROXY: case WINHTTP_OPTION_PROXY:
...@@ -391,49 +367,52 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe ...@@ -391,49 +367,52 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe
} }
case WINHTTP_OPTION_DISABLE_FEATURE: case WINHTTP_OPTION_DISABLE_FEATURE:
{ {
DWORD disable = *(DWORD *)buffer; DWORD disable;
if (buflen != sizeof(DWORD)) if (buflen != sizeof(DWORD))
{ {
SetLastError(ERROR_INSUFFICIENT_BUFFER); set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE; return FALSE;
} }
disable = *(DWORD *)buffer;
TRACE("0x%x\n", disable); TRACE("0x%x\n", disable);
hdr->disable_flags |= disable; hdr->disable_flags |= disable;
return TRUE; return TRUE;
} }
case WINHTTP_OPTION_AUTOLOGON_POLICY: case WINHTTP_OPTION_AUTOLOGON_POLICY:
{ {
DWORD policy = *(DWORD *)buffer; DWORD policy;
if (buflen != sizeof(DWORD)) if (buflen != sizeof(DWORD))
{ {
SetLastError(ERROR_INSUFFICIENT_BUFFER); set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE; return FALSE;
} }
policy = *(DWORD *)buffer;
TRACE("0x%x\n", policy); TRACE("0x%x\n", policy);
hdr->logon_policy = policy; hdr->logon_policy = policy;
return TRUE; return TRUE;
} }
case WINHTTP_OPTION_REDIRECT_POLICY: case WINHTTP_OPTION_REDIRECT_POLICY:
{ {
DWORD policy = *(DWORD *)buffer; DWORD policy;
if (buflen != sizeof(DWORD)) if (buflen != sizeof(DWORD))
{ {
SetLastError(ERROR_INSUFFICIENT_BUFFER); set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE; return FALSE;
} }
policy = *(DWORD *)buffer;
TRACE("0x%x\n", policy); TRACE("0x%x\n", policy);
hdr->redirect_policy = policy; hdr->redirect_policy = policy;
return TRUE; return TRUE;
} }
default: default:
FIXME("unimplemented option %u\n", option); FIXME("unimplemented option %u\n", option);
SetLastError(ERROR_INVALID_PARAMETER); set_last_error( ERROR_INVALID_PARAMETER );
return TRUE; return TRUE;
} }
} }
...@@ -531,10 +510,23 @@ static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPD ...@@ -531,10 +510,23 @@ static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPD
{ {
BOOL ret = FALSE; BOOL ret = FALSE;
if (!buflen)
{
set_last_error( ERROR_INVALID_PARAMETER );
return FALSE;
}
switch (option) switch (option)
{ {
case WINHTTP_OPTION_CONTEXT_VALUE: case WINHTTP_OPTION_CONTEXT_VALUE:
{ {
if (!buffer || *buflen < sizeof(DWORD_PTR))
{
*buflen = sizeof(DWORD_PTR);
set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE;
}
*(DWORD_PTR *)buffer = hdr->context; *(DWORD_PTR *)buffer = hdr->context;
*buflen = sizeof(DWORD_PTR); *buflen = sizeof(DWORD_PTR);
return TRUE; return TRUE;
...@@ -544,7 +536,7 @@ static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPD ...@@ -544,7 +536,7 @@ static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPD
else else
{ {
FIXME("unimplemented option %u\n", option); FIXME("unimplemented option %u\n", option);
SetLastError(ERROR_WINHTTP_INCORRECT_HANDLE_TYPE); set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
return FALSE; return FALSE;
} }
break; break;
...@@ -578,10 +570,22 @@ static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD ...@@ -578,10 +570,22 @@ static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD
{ {
BOOL ret = TRUE; BOOL ret = TRUE;
if (!buffer)
{
set_last_error( ERROR_INVALID_PARAMETER );
return FALSE;
}
switch (option) switch (option)
{ {
case WINHTTP_OPTION_CONTEXT_VALUE: case WINHTTP_OPTION_CONTEXT_VALUE:
{ {
if (buflen != sizeof(DWORD_PTR))
{
set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE;
}
hdr->context = *(DWORD_PTR *)buffer; hdr->context = *(DWORD_PTR *)buffer;
return TRUE; return TRUE;
} }
...@@ -590,7 +594,7 @@ static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD ...@@ -590,7 +594,7 @@ static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD
else else
{ {
FIXME("unimplemented option %u\n", option); FIXME("unimplemented option %u\n", option);
SetLastError(ERROR_WINHTTP_INCORRECT_HANDLE_TYPE); set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
return FALSE; return FALSE;
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment