Bug 856506 - Fix crash in nsSmtpProtocol when parsing IDN. r=Standard8
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 09 Apr 2013 20:46:12 +0100
changeset 12297 96d7f4197146
parent 12296 10d2778de689
child 12298 d3b26176b0df
push id9092
push userbugzilla@standard8.plus.com
push date2013-04-14 15:36 +0000
treeherdercomm-central@96d7f4197146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs856506
Bug 856506 - Fix crash in nsSmtpProtocol when parsing IDN. r=Standard8
mailnews/compose/src/nsSmtpProtocol.cpp
mailnews/compose/test/unit/test_sendMailAddressIDN.js
--- a/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -1768,17 +1768,17 @@ nsresult nsSmtpProtocol::LoadUrl(nsIURI 
           if (firstEvil)
           {
             // Fortunately, we will always have an @ in each mailbox address.
             // We try to fix illegal character in the domain part by converting
             // that to ACE. Illegal characters in the local part are not fixable
             // (which charset would it be anyway?), hence we error out in that
             // case as well.
             nsresult rv = NS_ERROR_FAILURE; // anything but NS_OK
-            if (firstEvil > lastAt)
+            if (lastAt && firstEvil > lastAt)
             {
               // illegal char in the domain part, hence use ACE
               nsAutoCString domain;
               domain.Assign(lastAt + 1, i - lastAt - 1);
               rv = converter->ConvertUTF8toACE(domain, domain);
               if (NS_SUCCEEDED(rv))
               {
                 addresses.Append(start, lastAt - start + 1);
--- a/mailnews/compose/test/unit/test_sendMailAddressIDN.js
+++ b/mailnews/compose/test/unit/test_sendMailAddressIDN.js
@@ -13,22 +13,27 @@ var sentFolder;
 var originalData;
 var expectedAlertMessage;
 
 const kSender     = "from@foo.invalid";
 const kToASCII    = "to@foo.invalid";
 const kToValid    = "to@v\u00E4lid.foo.invalid";
 const kToValidACE = "to@xn--vlid-loa.foo.invalid";
 const kToInvalid  = "b\u00F8rken.to@invalid.foo.invalid";
+const kToInvalidWithoutDomain = "b\u00F8rken.to";
 const NS_ERROR_BUT_DONT_SHOW_ALERT = 0x805530ef;
 
 
 // nsIPrompt
 function alert(aDialogText, aText)
 {
+  // ignore without domain situation (this is crash test)
+  if (test == kToInvalidWithoutDomain)
+    return;
+
   // we should only get here for the kToInvalid test case
   do_check_eq(test, kToInvalid);
   do_check_eq(aText, expectedAlertMessage);
 }
 
 
 // message listener implementations
 function msgListener(aRecipient)
@@ -194,9 +199,14 @@ function run_test()
   // Test 3:
   // The recipient's local part contains a non-ASCII character, which is not
   // allowed with unextended SMTP.
   // The old code would just strip the invalid character and try to send the
   // message to the remaining - wrong! - address.
   // The new code will present an informational message box and deny sending.
   test = kToInvalid;
   DoSendTest(kToInvalid, kToInvalid, NS_ERROR_BUT_DONT_SHOW_ALERT);
+
+  // Test 4:
+  // Bug 856506. invalid char without '@' casues crash.
+  test = kToInvalidWithoutDomain;
+  DoSendTest(kToInvalidWithoutDomain, kToInvalidWithoutDomain, NS_ERROR_BUT_DONT_SHOW_ALERT);
 }