Bug 898156 - Crash in thumbnail generation @ mozilla::net::FTPChannelParent::OnStartRequest. r=mcmanus, a=akeybl
authorJason Duell <jduell.mcbugs@gmail.com>
Wed, 11 Sep 2013 01:10:59 -0700
changeset 149324 1708e75f93f570e9e5ce728250edaa14ed897967
parent 149323 5706a9c6704a0e60c3bc4208d575a5cab2b47fe4
child 149325 97e0d6a036967228b3fe2cef8d932841978cc943
push id4240
push userryanvm@gmail.com
push dateThu, 12 Sep 2013 13:47:36 +0000
treeherdermozilla-aurora@1708e75f93f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, akeybl
bugs898156
milestone25.0a2
Bug 898156 - Crash in thumbnail generation @ mozilla::net::FTPChannelParent::OnStartRequest. r=mcmanus, a=akeybl
netwerk/protocol/ftp/FTPChannelParent.cpp
--- a/netwerk/protocol/ftp/FTPChannelParent.cpp
+++ b/netwerk/protocol/ftp/FTPChannelParent.cpp
@@ -185,31 +185,49 @@ FTPChannelParent::RecvResume()
 // FTPChannelParent::nsIRequestObserver
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 FTPChannelParent::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
 {
   LOG(("FTPChannelParent::OnStartRequest [this=%p]\n", this));
 
-  nsFtpChannel* chan = static_cast<nsFtpChannel*>(aRequest);
+  nsCOMPtr<nsIChannel> chan = do_QueryInterface(aRequest);
+  MOZ_ASSERT(chan);
+  NS_ENSURE_TRUE(chan, NS_ERROR_UNEXPECTED);
+
   int64_t contentLength;
   chan->GetContentLength(&contentLength);
   nsCString contentType;
   chan->GetContentType(contentType);
+
   nsCString entityID;
-  chan->GetEntityID(entityID);
-  PRTime lastModified;
-  chan->GetLastModifiedTime(&lastModified);
+  nsCOMPtr<nsIResumableChannel> resChan = do_QueryInterface(aRequest);
+  MOZ_ASSERT(resChan); // both FTP and HTTP should implement nsIResumableChannel
+  if (resChan) {
+    resChan->GetEntityID(entityID);
+  }
 
-  URIParams uri;
-  SerializeURI(chan->URI(), uri);
+  nsCOMPtr<nsIFTPChannel> ftpChan = do_QueryInterface(aRequest);
+  PRTime lastModified = 0;
+  if (ftpChan) {
+    ftpChan->GetLastModifiedTime(&lastModified);
+  } else {
+    // Temporary hack: if we were redirected to use an HTTP channel (ie FTP is
+    // using an HTTP proxy), cancel, as we don't support those redirects yet.
+    aRequest->Cancel(NS_ERROR_NOT_IMPLEMENTED);
+  }
+
+  URIParams uriparam;
+  nsCOMPtr<nsIURI> uri;
+  chan->GetURI(getter_AddRefs(uri));
+  SerializeURI(uri, uriparam);
 
   if (mIPCClosed || !SendOnStartRequest(contentLength, contentType,
-                                       lastModified, entityID, uri)) {
+                                       lastModified, entityID, uriparam)) {
     return NS_ERROR_UNEXPECTED;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 FTPChannelParent::OnStopRequest(nsIRequest* aRequest,