From e6d4a8daf3497986d55bd4b4cfd85b11bc5684d1 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Fri, 4 May 2018 10:20:16 +0200 Subject: Issue #325 Part 1: Remove the legacy non-IDNA2008 code path from nsIDNService. --- netwerk/dns/nsIDNService.cpp | 120 +------------------------------------------ 1 file changed, 2 insertions(+), 118 deletions(-) (limited to 'netwerk/dns/nsIDNService.cpp') diff --git a/netwerk/dns/nsIDNService.cpp b/netwerk/dns/nsIDNService.cpp index 49beecbb3..31ba12b4c 100644 --- a/netwerk/dns/nsIDNService.cpp +++ b/netwerk/dns/nsIDNService.cpp @@ -17,7 +17,6 @@ #include "nsISupportsPrimitives.h" #include "punycode.h" -#ifdef IDNA2008 // Currently we use the non-transitional processing option -- see // http://unicode.org/reports/tr46/ // To switch to transitional processing, change the value of this flag @@ -27,7 +26,6 @@ const bool kIDNA2008_TransitionalProcessing = false; #include "ICUUtils.h" #include "unicode/uscript.h" -#endif using namespace mozilla::unicode; @@ -136,32 +134,19 @@ nsIDNService::nsIDNService() : mShowPunycode(false) , mIDNUseWhitelist(false) { -#ifdef IDNA2008 uint32_t IDNAOptions = UIDNA_CHECK_BIDI | UIDNA_CHECK_CONTEXTJ; if (!kIDNA2008_TransitionalProcessing) { IDNAOptions |= UIDNA_NONTRANSITIONAL_TO_UNICODE; } UErrorCode errorCode = U_ZERO_ERROR; mIDNA = uidna_openUTS46(IDNAOptions, &errorCode); -#else - if (idn_success != idn_nameprep_create(nullptr, &mNamePrepHandle)) - mNamePrepHandle = nullptr; - - mNormalizer = do_GetService(NS_UNICODE_NORMALIZER_CONTRACTID); - /* member initializers and constructor code */ -#endif } nsIDNService::~nsIDNService() { -#ifdef IDNA2008 uidna_close(mIDNA); -#else - idn_nameprep_destroy(mNamePrepHandle); -#endif } -#ifdef IDNA2008 nsresult nsIDNService::IDNA2008ToUnicode(const nsACString& input, nsAString& output) { @@ -226,7 +211,6 @@ nsIDNService::IDNA2008StringPrep(const nsAString& input, return rv; } -#endif NS_IMETHODIMP nsIDNService::ConvertUTF8toACE(const nsACString & input, nsACString & ace) { @@ -486,21 +470,6 @@ static nsresult utf16ToUcs4(const nsAString& in, return NS_OK; } -#ifndef IDNA2008 -static void ucs4toUtf16(const uint32_t *in, nsAString& out) -{ - while (*in) { - if (!IS_IN_BMP(*in)) { - out.Append((char16_t) H_SURROGATE(*in)); - out.Append((char16_t) L_SURROGATE(*in)); - } - else - out.Append((char16_t) *in); - in++; - } -} -#endif - static nsresult punycode(const nsAString& in, nsACString& out) { uint32_t ucs4Buf[kMaxDNSNodeLen + 1]; @@ -551,74 +520,12 @@ static nsresult punycode(const nsAString& in, nsACString& out) // any unassigned Unicode points and if any are found return an error. // This is described in section 7. // +// => All this is handled by ICU's StringPrep(). +// nsresult nsIDNService::stringPrep(const nsAString& in, nsAString& out, stringPrepFlag flag) { -#ifdef IDNA2008 return IDNA2008StringPrep(in, out, flag); -#else - if (!mNamePrepHandle || !mNormalizer) - return NS_ERROR_FAILURE; - - uint32_t ucs4Buf[kMaxDNSNodeLen + 1]; - uint32_t ucs4Len; - nsresult rv = utf16ToUcs4(in, ucs4Buf, kMaxDNSNodeLen, &ucs4Len); - NS_ENSURE_SUCCESS(rv, rv); - - // map - idn_result_t idn_err; - - uint32_t namePrepBuf[kMaxDNSNodeLen * 3]; // map up to three characters - idn_err = idn_nameprep_map(mNamePrepHandle, (const uint32_t *) ucs4Buf, - (uint32_t *) namePrepBuf, kMaxDNSNodeLen * 3); - NS_ENSURE_TRUE(idn_err == idn_success, NS_ERROR_MALFORMED_URI); - - nsAutoString namePrepStr; - ucs4toUtf16(namePrepBuf, namePrepStr); - if (namePrepStr.Length() >= kMaxDNSNodeLen) - return NS_ERROR_MALFORMED_URI; - - // normalize - nsAutoString normlizedStr; - rv = mNormalizer->NormalizeUnicodeNFKC(namePrepStr, normlizedStr); - if (normlizedStr.Length() >= kMaxDNSNodeLen) - return NS_ERROR_MALFORMED_URI; - - // set the result string - out.Assign(normlizedStr); - - if (flag == eStringPrepIgnoreErrors) { - return NS_OK; - } - - // prohibit - const uint32_t *found = nullptr; - idn_err = idn_nameprep_isprohibited(mNamePrepHandle, - (const uint32_t *) ucs4Buf, &found); - if (idn_err != idn_success || found) { - rv = NS_ERROR_MALFORMED_URI; - } else { - // check bidi - idn_err = idn_nameprep_isvalidbidi(mNamePrepHandle, - (const uint32_t *) ucs4Buf, &found); - if (idn_err != idn_success || found) { - rv = NS_ERROR_MALFORMED_URI; - } else if (flag == eStringPrepForUI) { - // check unassigned code points - idn_err = idn_nameprep_isunassigned(mNamePrepHandle, - (const uint32_t *) ucs4Buf, &found); - if (idn_err != idn_success || found) { - rv = NS_ERROR_MALFORMED_URI; - } - } - } - - if (flag == eStringPrepForDNS && NS_FAILED(rv)) { - out.Truncate(); - } - - return rv; -#endif } nsresult nsIDNService::stringPrepAndACE(const nsAString& in, nsACString& out, @@ -709,31 +616,8 @@ nsresult nsIDNService::decodeACE(const nsACString& in, nsACString& out, } nsAutoString utf16; -#ifdef IDNA2008 nsresult result = IDNA2008ToUnicode(in, utf16); NS_ENSURE_SUCCESS(result, result); -#else - // RFC 3490 - 4.2 ToUnicode - // The ToUnicode output never contains more code points than its input. - punycode_uint output_length = in.Length() - kACEPrefixLen + 1; - auto *output = new punycode_uint[output_length]; - NS_ENSURE_TRUE(output, NS_ERROR_OUT_OF_MEMORY); - - enum punycode_status status = punycode_decode(in.Length() - kACEPrefixLen, - PromiseFlatCString(in).get() + kACEPrefixLen, - &output_length, - output, - nullptr); - if (status != punycode_success) { - delete [] output; - return NS_ERROR_MALFORMED_URI; - } - - // UCS4 -> UTF8 - output[output_length] = 0; - ucs4toUtf16(output, utf16); - delete [] output; -#endif if (flag != eStringPrepForUI || isLabelSafe(utf16)) { CopyUTF16toUTF8(utf16, out); } else { -- cgit v1.2.3