From 9b0c307f8a9efaebd96396c8fa9327c07f25e43d Mon Sep 17 00:00:00 2001 From: "asqueella%gmail.com" Date: Wed, 25 Apr 2007 20:48:28 +0000 Subject: [PATCH] Bug 368700 - Using TLDs in document.domain should not be allowed p=Wladimir Palant r=bz, sr=dveditz git-svn-id: svn://10.0.0.236/trunk@225037 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLDocument.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index b0fa8ed6f86..d14a8e713d5 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -126,6 +126,7 @@ #include "nsIScriptError.h" #include "nsIMutableArray.h" #include "nsArrayUtils.h" +#include "nsIEffectiveTLDService.h" #include "nsIPrompt.h" //AHMED 12-2 @@ -1641,8 +1642,22 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain) current.Right(suffix, aDomain.Length()); PRUnichar c = current.CharAt(current.Length() - aDomain.Length() - 1); if (suffix.Equals(aDomain, nsCaseInsensitiveStringComparator()) && - (c == '.')) - ok = PR_TRUE; + (c == '.')) { + // Using only a TLD is forbidden (bug 368700) + nsCOMPtr tldService = + do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID); + if (!tldService) + return NS_ERROR_NOT_AVAILABLE; + + NS_ConvertUTF16toUTF8 str(aDomain); + PRUint32 tldLength; + nsresult rv = tldService->GetEffectiveTLDLength(str, &tldLength); + if (NS_FAILED(rv)) + return rv; + + if (tldLength < str.Length()) + ok = PR_TRUE; + } } if (!ok) { // Error: illegal domain