Only test IDN nodes against kMaxDNSNodeLen on string-prepped IDNs that we're going to send to DNS, not the Unicode form for display only. Bug 892370, r=honzab, a=bajaj
authorSimon Montagu <smontagu@smontagu.org>
Wed, 21 Aug 2013 09:18:17 +0300
changeset 148401 48b14885dccee24988594e9fcc541d1da123dd11
parent 148400 1da154975a24fd93c1325cc98c4f5d1647524ea9
child 148402 2819dba1a303520c1e59682340035c5707261d95
push id2786
push usersmontagu@mozilla.com
push dateWed, 21 Aug 2013 06:18:42 +0000
treeherdermozilla-beta@48b14885dcce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab, bajaj
bugs892370
milestone24.0
Only test IDN nodes against kMaxDNSNodeLen on string-prepped IDNs that we're going to send to DNS, not the Unicode form for display only. Bug 892370, r=honzab, a=bajaj
netwerk/dns/nsIDNService.cpp
netwerk/test/unit/test_idn_urls.js
netwerk/test/unit/xpcshell.ini
--- a/netwerk/dns/nsIDNService.cpp
+++ b/netwerk/dns/nsIDNService.cpp
@@ -618,21 +618,26 @@ nsresult nsIDNService::stringPrepAndACE(
     nsAutoString strPrep;
     rv = stringPrep(in, strPrep, allowUnassigned);
     if (NS_SUCCEEDED(rv)) {
       if (IsASCII(strPrep))
         LossyCopyUTF16toASCII(strPrep, out);
       else
         rv = encodeToACE(strPrep, out);
     }
-  }
-
-  if (out.Length() > kMaxDNSNodeLen) {
-    NS_WARNING("IDN node too large");
-    return NS_ERROR_FAILURE;
+    // Check that the encoded output isn't larger than the maximum length of an
+    // DNS node per RFC 1034.
+    // This test isn't necessary in the code paths above where the input is
+    // ASCII (since the output will be the same length as the input) or where
+    // we convert to UTF-8 (since the output is only used for display in the
+    // UI and not passed to DNS and can legitimately be longer than the limit).
+    if (out.Length() > kMaxDNSNodeLen) {
+      NS_WARNING("IDN node too large");
+      return NS_ERROR_FAILURE;
+    }
   }
 
   return rv;
 }
 
 // RFC 3490
 // 1) Whenever dots are used as label separators, the following characters
 //    MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full
--- a/netwerk/test/unit/test_idn_urls.js
+++ b/netwerk/test/unit/test_idn_urls.js
@@ -265,17 +265,22 @@ const testcases = [
                  "xn--hangul-8m5th09k79ze",          false, true,  true],
 
     // Hangul and katakana
     ["한글ハングル",
                  "xn--qck1c2d4a9266lkmzb",           false, false, false],
 
     // Katakana and Hangul
     ["ハングル한글",
-                 "xn--qck1c2d4a2366lkmzb",           false, false, false]
+                 "xn--qck1c2d4a2366lkmzb",           false, false, false],
+
+    // Thai (also tests that node with over 63 UTF-8 octets doesn't fail)
+    ["เครื่องทําน้ําทําน้ําแข็ง",
+                 "xn--22cdjb2fanb9fyepcbbb9dwh4a3igze4fdcd",
+                                                     false, true, true]
 ];
 
 
 const profiles = ["ASCII", "high", "moderate"];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -72,17 +72,16 @@ tail =
 [test_bug654926_doom_and_read.js]
 [test_bug654926_test_seek.js]
 [test_bug659569.js]
 [test_bug660066.js]
 [test_bug667907.js]
 [test_bug667818.js]
 [test_bug669001.js]
 [test_bug712914_secinfo_validation.js]
-[test_bug722299.js]
 [test_bug770243.js]
 [test_doomentry.js]
 [test_cacheflags.js]
 [test_cache_jar.js]
 [test_channel_close.js]
 [test_compareURIs.js]
 [test_compressappend.js]
 [test_content_encoding_gzip.js]
@@ -113,16 +112,17 @@ tail =
 [test_head.js]
 [test_header_Accept-Language.js]
 [test_headers.js]
 [test_http_headers.js]
 [test_httpauth.js]
 [test_httpcancel.js]
 [test_httpsuspend.js]
 [test_idnservice.js]
+[test_idn_urls.js]
 [test_invalidport.js]
 [test_localstreams.js]
 [test_mismatch_last-modified.js]
 [test_MIME_params.js]
 [test_mozTXTToHTMLConv.js]
 [test_multipart_byteranges.js]
 [test_multipart_streamconv.js]
 [test_multipart_streamconv_missing_lead_boundary.js]