Commit f2a1737e authored by Thomas Mullaly's avatar Thomas Mullaly Committed by Alexandre Julliard

urlmon: Implemented validation of scheme component of a IUriBuilder.

parent 947e4ec5
...@@ -5085,6 +5085,25 @@ static const uri_builder_test uri_builder_tests[] = { ...@@ -5085,6 +5085,25 @@ static const uri_builder_test uri_builder_tests[] = {
{URL_SCHEME_HTTP,S_OK}, {URL_SCHEME_HTTP,S_OK},
{URLZONE_INVALID,E_NOTIMPL} {URLZONE_INVALID,E_NOTIMPL}
} }
},
{ NULL,0,S_OK,FALSE,
{
{TRUE,"/test/test/",NULL,Uri_PROPERTY_PATH,S_OK,FALSE},
{TRUE,"#Fr<|>g",NULL,Uri_PROPERTY_FRAGMENT,S_OK,FALSE}
},
{FALSE},
0,INET_E_INVALID_URL,FALSE,
0,INET_E_INVALID_URL,FALSE,
0,0,0,INET_E_INVALID_URL,FALSE
},
{ "http://google.com/",0,S_OK,FALSE,
{
{TRUE,"ht%xxtp",NULL,Uri_PROPERTY_SCHEME_NAME,S_OK,FALSE}
},
{FALSE},
0,INET_E_INVALID_URL,FALSE,
0,INET_E_INVALID_URL,FALSE,
0,0,0,INET_E_INVALID_URL,FALSE
} }
}; };
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#define UINT_MAX 0xffffffff #define UINT_MAX 0xffffffff
#define USHORT_MAX 0xffff #define USHORT_MAX 0xffff
#define ALLOW_NULL_TERM_SCHEME 0x1
WINE_DEFAULT_DEBUG_CHANNEL(urlmon); WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
static const IID IID_IUriObj = {0x4b364760,0x9f51,0x11df,{0x98,0x1c,0x08,0x00,0x20,0x0c,0x9a,0x66}}; static const IID IID_IUriObj = {0x4b364760,0x9f51,0x11df,{0x98,0x1c,0x08,0x00,0x20,0x0c,0x9a,0x66}};
...@@ -1148,7 +1150,7 @@ static BOOL check_ipv4address(const WCHAR **ptr, BOOL strict) { ...@@ -1148,7 +1150,7 @@ static BOOL check_ipv4address(const WCHAR **ptr, BOOL strict) {
* scheme = ALPHA *(ALPHA | NUM | '+' | '-' | '.') as defined by RFC 3896. * scheme = ALPHA *(ALPHA | NUM | '+' | '-' | '.') as defined by RFC 3896.
* NOTE: Windows accepts a number as the first character of a scheme. * NOTE: Windows accepts a number as the first character of a scheme.
*/ */
static BOOL parse_scheme_name(const WCHAR **ptr, parse_data *data) { static BOOL parse_scheme_name(const WCHAR **ptr, parse_data *data, DWORD extras) {
const WCHAR *start = *ptr; const WCHAR *start = *ptr;
data->scheme = NULL; data->scheme = NULL;
...@@ -1172,7 +1174,7 @@ static BOOL parse_scheme_name(const WCHAR **ptr, parse_data *data) { ...@@ -1172,7 +1174,7 @@ static BOOL parse_scheme_name(const WCHAR **ptr, parse_data *data) {
return FALSE; return FALSE;
/* Schemes must end with a ':' */ /* Schemes must end with a ':' */
if(**ptr != ':') { if(**ptr != ':' && !((extras & ALLOW_NULL_TERM_SCHEME) && !**ptr)) {
*ptr = start; *ptr = start;
return FALSE; return FALSE;
} }
...@@ -1225,7 +1227,7 @@ static BOOL parse_scheme_type(parse_data *data) { ...@@ -1225,7 +1227,7 @@ static BOOL parse_scheme_type(parse_data *data) {
* *
* Returns TRUE if it was able to successfully parse the information. * Returns TRUE if it was able to successfully parse the information.
*/ */
static BOOL parse_scheme(const WCHAR **ptr, parse_data *data, DWORD flags) { static BOOL parse_scheme(const WCHAR **ptr, parse_data *data, DWORD flags, DWORD extras) {
static const WCHAR fileW[] = {'f','i','l','e',0}; static const WCHAR fileW[] = {'f','i','l','e',0};
static const WCHAR wildcardW[] = {'*',0}; static const WCHAR wildcardW[] = {'*',0};
...@@ -1245,7 +1247,7 @@ static BOOL parse_scheme(const WCHAR **ptr, parse_data *data, DWORD flags) { ...@@ -1245,7 +1247,7 @@ static BOOL parse_scheme(const WCHAR **ptr, parse_data *data, DWORD flags) {
ptr, data, flags); ptr, data, flags);
return FALSE; return FALSE;
} }
} else if(!parse_scheme_name(ptr, data)) { } else if(!parse_scheme_name(ptr, data, extras)) {
/* No Scheme was found, this means it could be: /* No Scheme was found, this means it could be:
* a) an implicit Wildcard scheme * a) an implicit Wildcard scheme
* b) a relative URI * b) a relative URI
...@@ -2091,7 +2093,7 @@ static BOOL parse_uri(parse_data *data, DWORD flags) { ...@@ -2091,7 +2093,7 @@ static BOOL parse_uri(parse_data *data, DWORD flags) {
TRACE("(%p %x): BEGINNING TO PARSE URI %s.\n", data, flags, debugstr_w(data->uri)); TRACE("(%p %x): BEGINNING TO PARSE URI %s.\n", data, flags, debugstr_w(data->uri));
if(!parse_scheme(pptr, data, flags)) if(!parse_scheme(pptr, data, flags, 0))
return FALSE; return FALSE;
if(!parse_hierpart(pptr, data, flags)) if(!parse_hierpart(pptr, data, flags))
...@@ -3407,9 +3409,58 @@ static void reset_builder(UriBuilder *builder) { ...@@ -3407,9 +3409,58 @@ static void reset_builder(UriBuilder *builder) {
builder->modified_props = 0; builder->modified_props = 0;
} }
static HRESULT validate_scheme_name(const UriBuilder *builder, parse_data *data, DWORD flags) {
const WCHAR *ptr;
const WCHAR **pptr;
DWORD expected_len;
if(builder->scheme) {
ptr = builder->scheme;
expected_len = builder->scheme_len;
} else if(builder->uri && builder->uri->scheme_start > -1) {
ptr = builder->uri->canon_uri+builder->uri->scheme_start;
expected_len = builder->uri->scheme_len;
} else {
static const WCHAR nullW[] = {0};
ptr = nullW;
expected_len = 0;
}
pptr = &ptr;
if(parse_scheme(pptr, data, flags, ALLOW_NULL_TERM_SCHEME) &&
data->scheme_len == expected_len) {
if(data->scheme)
TRACE("(%p %p %x): Found valid scheme component %s.\n", builder, data, flags,
debugstr_wn(data->scheme, data->scheme_len));
} else {
TRACE("(%p %p %x): Invalid scheme component found %s.\n", builder, data, flags,
debugstr_wn(ptr, expected_len));
return INET_E_INVALID_URL;
}
return S_OK;
}
static HRESULT validate_components(const UriBuilder *builder, parse_data *data, DWORD flags) {
HRESULT hr;
memset(data, 0, sizeof(parse_data));
TRACE("(%p %p %x): Beginning to validate builder components.\n", builder, data, flags);
hr = validate_scheme_name(builder, data, flags);
if(FAILED(hr))
return hr;
return E_NOTIMPL;
}
static HRESULT build_uri(const UriBuilder *builder, IUri **uri, DWORD create_flags, static HRESULT build_uri(const UriBuilder *builder, IUri **uri, DWORD create_flags,
DWORD use_orig_flags, DWORD encoding_mask) DWORD use_orig_flags, DWORD encoding_mask)
{ {
HRESULT hr;
parse_data data;
if(!uri) if(!uri)
return E_POINTER; return E_POINTER;
...@@ -3438,7 +3489,13 @@ static HRESULT build_uri(const UriBuilder *builder, IUri **uri, DWORD create_fla ...@@ -3438,7 +3489,13 @@ static HRESULT build_uri(const UriBuilder *builder, IUri **uri, DWORD create_fla
return S_OK; return S_OK;
} }
return E_NOTIMPL; hr = validate_components(builder, &data, create_flags);
if(FAILED(hr)) {
*uri = NULL;
return hr;
}
return S_OK;
} }
#define URI_THIS(iface) DEFINE_THIS(Uri, IUri, iface) #define URI_THIS(iface) DEFINE_THIS(Uri, IUri, iface)
......
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