Bug 392729 - Links for nntp and news Protocols Ignored or crash [@ nsNntpService::MessageURIToMsgHdr(char const*, nsIMsgDBHdr**) ]. r=bienvenu+jcranmer
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 06 Dec 2010 14:16:46 +0900
changeset 6796 a02c207dff032a746bd644753271ed852f5a23bc
parent 6795 07d07bebd7f0723f27f1e465e301a6cb1809153b
child 6797 d79b6317572498272fd194c52df65b6db6fb0184
push idunknown
push userunknown
push dateunknown
reviewersbienvenu
bugs392729
Bug 392729 - Links for nntp and news Protocols Ignored or crash [@ nsNntpService::MessageURIToMsgHdr(char const*, nsIMsgDBHdr**) ]. r=bienvenu+jcranmer
mailnews/news/src/nsNntpService.cpp
mailnews/news/test/unit/test_nntpUrl.js
--- a/mailnews/news/src/nsNntpService.cpp
+++ b/mailnews/news/src/nsNntpService.cpp
@@ -591,18 +591,18 @@ nsNntpService::DecomposeNewsMessageURI(c
       mailnewsurl->SetSpec(nsDependentCString(aMessageURI));
 
       // get group name and message key
       groupName = Substring(newsUrl, groupPos + kNewsURIGroupQueryLen,
                             keyPos - groupPos - kNewsURIGroupQueryLen);
       keyStr = Substring(newsUrl, keyPos + kNewsURIKeyQueryLen);
       // get message key
       nsMsgKey key = nsMsgKey_None;
-      nsresult errorCode;
-      key = keyStr.ToInteger(&errorCode, 10);
+      key = keyStr.ToInteger(&rv, 10);
+      NS_ENSURE_SUCCESS(rv,rv);
 
       // get userPass
       nsCAutoString userPass;
       rv = mailnewsurl->GetUserPass(userPass);
       NS_ENSURE_SUCCESS(rv,rv);
 
       // get hostName
       nsCAutoString hostName;
@@ -627,29 +627,31 @@ nsNntpService::DecomposeNewsMessageURI(c
       NS_ENSURE_SUCCESS(rv,rv);
 
       // get msg folder for group name
       nsCOMPtr<nsIMsgFolder> child;
       rv = rootFolder->GetChildNamed(NS_ConvertUTF8toUTF16(groupName),
                                      getter_AddRefs(child));
       NS_ENSURE_SUCCESS(rv,rv);
 
-      if (!errorCode)
-      {
-        child.swap(*aFolder);
-        *aMsgKey = key;
-      }
+      child.swap(*aFolder);
+      *aMsgKey = key;
     }
     else
     {
       rv = GetFolderFromUri(aMessageURI, aFolder);
       NS_ENSURE_SUCCESS(rv,rv);
       *aMsgKey = nsMsgKey_None;
     }
   }
+  else
+  {
+    // This schema isn't supported
+    return NS_ERROR_INVALID_ARG;
+  }
 
   return NS_OK;
 }
 
 nsresult
 nsNntpService::GetFolderFromUri(const char *aUri, nsIMsgFolder **aFolder)
 {
   NS_ENSURE_ARG_POINTER(aUri);
new file mode 100644
--- /dev/null
+++ b/mailnews/news/test/unit/test_nntpUrl.js
@@ -0,0 +1,39 @@
+/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ *
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+function getMessageHeaderFromUrl(aUrl) {
+  let msgUrl = Cc["@mozilla.org/messenger/messageservice;1?type=news"]
+                .getService(Ci.nsINntpService)
+                .QueryInterface(Ci.nsIProtocolHandler)
+                .newURI(aUrl, null, null)
+                .QueryInterface(Ci.nsIMsgMessageUrl);
+  return msgUrl.messageHeader;
+}
+
+function run_test() {
+
+  // This is crash test for Bug 392729
+
+  try {
+    // nntp:// protocol isn't supported yet until bug 226890 is fixed.
+    // When We pass invlid nntp:// protocol format, we should throw a exception.
+    let hdr = getMessageHeaderFromUrl("nntp://localhost:" + NNTP_PORT);
+    do_check_true(false); 
+  } catch (e) {
+    do_check_true(e.result == Components.results.NS_ERROR_ILLEGAL_VALUE);
+  }
+
+  try {
+    // msgkey is invalid for news:// protocol
+    let hdr = getMessageHeaderFromUrl("news://localhost:" + NNTP_PORT +
+                                      "/message-id?group=test.subscribe.simple&key=abcdefghijk");
+    do_check_true(false); 
+  } catch (e) {
+    do_check_true(e.result == Components.results.NS_ERROR_ILLEGAL_VALUE);
+  }
+}