Bug 394525: don't try to malware check uris with no hostname. r=tony

This commit is contained in:
dcamp@mozilla.com 2007-11-27 12:08:02 -08:00
Родитель 063f955987
Коммит 96f51a6327
3 изменённых файлов: 30 добавлений и 2 удалений

Просмотреть файл

@ -2241,8 +2241,15 @@ nsUrlClassifierDBService::Classify(nsIURI *uri,
new nsUrlClassifierClassifyCallback(c);
if (!callback) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = LookupURI(uri, callback, PR_TRUE);
if (rv == NS_ERROR_MALFORMED_URI) {
// The URI had no hostname, don't try to classify it.
*result = PR_FALSE;
return NS_OK;
}
*result = PR_TRUE;
return LookupURI(uri, callback, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -130,6 +130,10 @@ nsUrlClassifierUtils::GetKeyForURI(nsIURI * uri, nsACString & _retval)
nsCAutoString host;
innerURI->GetAsciiHost(host);
if (host.IsEmpty()) {
return NS_ERROR_MALFORMED_URI;
}
nsresult rv = CanonicalizeHostname(host, _retval);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -55,6 +55,22 @@ function testFailure(arg) {
do_throw(arg);
}
function checkNoHost()
{
// Looking up a no-host uri such as a data: uri should throw an exception.
var exception;
try {
dbservice.lookup("data:text/html,<b>test</b>");
exception = false;
} catch(e) {
exception = true;
}
do_check_true(exception);
do_test_finished();
}
function tablesCallback(tables)
{
var parts = tables.split("\n");
@ -63,7 +79,8 @@ function tablesCallback(tables)
// after the trailing newline, which will sort first
do_check_eq(parts.join("\n"),
"\ntesting-malware-simple;a:1\ntesting-phish-simple;a:2:s:3");
do_test_finished();
checkNoHost();
}
function checkChunks()