shlwapi: Make more strict restriction for URL scheme and fix error handling in ParseURLW.

This commit is contained in:
Jacek Caban 2009-10-18 21:49:41 +02:00 committed by Alexandre Julliard
parent e57b8526b2
commit 4d592ae84f
2 changed files with 15 additions and 27 deletions

View File

@ -131,7 +131,7 @@ static const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
{"res:///c:\\tests\\foo bar", 0, S_OK, "res:///c:\\tests\\foo bar", TRUE},
{"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "res:///c:\\tests\\foo bar", TRUE},
{"A", 0, S_OK, "A", FALSE},
{"/uri-res/N2R?urn:sha1:B3K", URL_DONT_ESCAPE_EXTRA_INFO | URL_WININET_COMPATIBILITY /*0x82000000*/, S_OK, "/uri-res/N2R?urn:sha1:B3K", TRUE} /*LimeWire online installer calls this*/,
{"/uri-res/N2R?urn:sha1:B3K", URL_DONT_ESCAPE_EXTRA_INFO | URL_WININET_COMPATIBILITY /*0x82000000*/, S_OK, "/uri-res/N2R?urn:sha1:B3K", FALSE} /*LimeWire online installer calls this*/,
{"http:www.winehq.org/dir/../index.html", 0, S_OK, "http:www.winehq.org/index.html"},
};

View File

@ -180,38 +180,26 @@ HRESULT WINAPI ParseURLA(LPCSTR x, PARSEDURLA *y)
*/
HRESULT WINAPI ParseURLW(LPCWSTR x, PARSEDURLW *y)
{
DWORD cnt;
const WCHAR *ptr = x;
y->nScheme = URL_SCHEME_INVALID;
if (y->cbSize != sizeof(*y)) return E_INVALIDARG;
/* FIXME: leading white space generates error of 0x80041001 which
* is undefined
*/
if (*x <= ' ') return 0x80041001;
cnt = 0;
y->cchProtocol = 0;
y->pszProtocol = x;
while (*x) {
if (*x == ':') {
y->cchProtocol = cnt;
cnt = -1;
y->pszSuffix = x+1;
break;
}
x++;
cnt++;
}
TRACE("%s %p\n", debugstr_w(x), y);
/* check for no scheme in string start */
/* (apparently schemes *must* be larger than a single character) */
if ((*x == '\0') || (y->cchProtocol <= 1)) {
if(y->cbSize != sizeof(*y))
return E_INVALIDARG;
while(*ptr && (isalnumW(*ptr) || *ptr == '-'))
ptr++;
if (*ptr != ':' || ptr <= x+1) {
y->pszProtocol = NULL;
return 0x80041001;
}
/* found scheme, set length of remainder */
y->cchSuffix = lstrlenW(y->pszSuffix);
y->nScheme = get_scheme_code(y->pszProtocol, y->cchProtocol);
y->pszProtocol = x;
y->cchProtocol = ptr-x;
y->pszSuffix = ptr+1;
y->cchSuffix = strlenW(y->pszSuffix);
y->nScheme = get_scheme_code(x, ptr-x);
return S_OK;
}