Bug 934805 - Ensure client code passes in sane argument to baseDomain functions. r=hurley

This commit is contained in:
Jason Duell 2013-11-15 21:46:39 -05:00
parent 2046aafb3c
commit fbc531c9b5

View File

@ -166,6 +166,7 @@ nsEffectiveTLDService::GetBaseDomain(nsIURI *aURI,
nsACString &aBaseDomain) nsACString &aBaseDomain)
{ {
NS_ENSURE_ARG_POINTER(aURI); NS_ENSURE_ARG_POINTER(aURI);
NS_ENSURE_TRUE( ((int32_t)aAdditionalParts) >= 0, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI); nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
NS_ENSURE_ARG_POINTER(innerURI); NS_ENSURE_ARG_POINTER(innerURI);
@ -200,6 +201,8 @@ nsEffectiveTLDService::GetBaseDomainFromHost(const nsACString &aHostname,
uint32_t aAdditionalParts, uint32_t aAdditionalParts,
nsACString &aBaseDomain) nsACString &aBaseDomain)
{ {
NS_ENSURE_TRUE( ((int32_t)aAdditionalParts) >= 0, NS_ERROR_INVALID_ARG);
// Create a mutable copy of the hostname and normalize it to ACE. // Create a mutable copy of the hostname and normalize it to ACE.
// This will fail if the hostname includes invalid characters. // This will fail if the hostname includes invalid characters.
nsAutoCString normHostname(aHostname); nsAutoCString normHostname(aHostname);
@ -300,7 +303,7 @@ nsEffectiveTLDService::GetBaseDomainInternal(nsCString &aHostname,
const char *begin, *iter; const char *begin, *iter;
if (aAdditionalParts < 0) { if (aAdditionalParts < 0) {
NS_ASSERTION(aAdditionalParts == -1, NS_ASSERTION(aAdditionalParts == -1,
"aAdditionalParts should can't be negative and different from -1"); "aAdditionalParts can't be negative and different from -1");
for (iter = aHostname.get(); iter != eTLD && *iter != '.'; iter++); for (iter = aHostname.get(); iter != eTLD && *iter != '.'; iter++);