From 55fd3921f7aa88ba0b00991f263b834cdc6f2646 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Sun, 29 Sep 2002 16:50:08 +0000 Subject: [PATCH] Fixes topcrash 171333 crash at startup in nsFileChannel if chrome modified [@ nsFileChannel::GetFile] r=danm@netscape.com, sr=brendan@mozilla.org --- netwerk/protocol/file/src/nsFileChannel.cpp | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/netwerk/protocol/file/src/nsFileChannel.cpp b/netwerk/protocol/file/src/nsFileChannel.cpp index 78b878e5d750..4d1bbec4e2a3 100644 --- a/netwerk/protocol/file/src/nsFileChannel.cpp +++ b/netwerk/protocol/file/src/nsFileChannel.cpp @@ -51,7 +51,7 @@ #include "nsInt64.h" #include "nsMimeTypes.h" #include "nsNetUtil.h" -#include "prio.h" // Need to pick up def of PR_RDONLY +#include "prio.h" // Need to pick up def of PR_RDONLY static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); @@ -259,9 +259,7 @@ nsFileChannel::EnsureFile() nsresult nsFileChannel::GetFileTransport(nsITransport **trans) { - nsresult rv = NS_OK; - - rv = EnsureFile(); + nsresult rv = EnsureFile(); if (NS_FAILED(rv)) return rv; @@ -458,6 +456,10 @@ nsFileChannel::SetContentCharset(const nsACString &aContentCharset) NS_IMETHODIMP nsFileChannel::GetContentLength(PRInt32 *aContentLength) { + if (!mFile) { + return NS_ERROR_NOT_AVAILABLE; + } + nsresult rv; PRInt64 size; rv = mFile->GetFileSize(&size); @@ -551,8 +553,12 @@ nsFileChannel::OnStartRequest(nsIRequest* request, nsISupports* context) NS_ASSERTION(mRealListener, "No listener..."); nsresult rv = NS_OK; if (mRealListener) { - if (mGenerateHTMLDirs) - { + if (mGenerateHTMLDirs) { + // GetFileTransport ensures that mFile is valid before calling + // AsyncRead or AsyncWrite on the underlying transport. Since + // these transports use |this| as the nsIRequestObserver, there + // should be no way that mFile is null here. + NS_ENSURE_TRUE(mFile, NS_ERROR_UNEXPECTED); PRBool directory; mFile->IsDirectory(&directory); // this stat should be cached and will not hit disk. if (directory) { @@ -724,6 +730,10 @@ nsFileChannel::Init(nsIFile* file, NS_IMETHODIMP nsFileChannel::GetFile(nsIFile* *result) { + nsresult rv = EnsureFile(); + if (NS_FAILED(rv)) + return rv; + *result = mFile; NS_ADDREF(*result); return NS_OK;