Bug 1035394 - Fix dangerous public destructors in netwerk - r=mcmanus
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 08 Jul 2014 17:23:18 -0400
changeset 192898 5821b55a574cfd078b7f3f9eeba2d497c2993254
parent 192897 d070ae6e63cb7e538b6deee90c30b698fd380995
child 192899 2f5b2fbae4fbfb698ce38a841cc9c694335921db
push id45969
push userbjacob@mozilla.com
push dateTue, 08 Jul 2014 21:27:57 +0000
treeherdermozilla-inbound@558231b7c91c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1035394
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1035394 - Fix dangerous public destructors in netwerk - r=mcmanus
netwerk/base/src/nsBufferedStreams.h
netwerk/base/src/nsFileStreams.h
netwerk/cache2/OldWrappers.h
netwerk/protocol/device/nsDeviceChannel.h
netwerk/protocol/file/nsFileChannel.cpp
netwerk/protocol/file/nsFileChannel.h
netwerk/protocol/ftp/FTPChannelChild.h
netwerk/protocol/http/nsHttpChannel.h
--- a/netwerk/base/src/nsBufferedStreams.h
+++ b/netwerk/base/src/nsBufferedStreams.h
@@ -66,26 +66,27 @@ class nsBufferedInputStream : public nsB
 public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSIINPUTSTREAM
     NS_DECL_NSIBUFFEREDINPUTSTREAM
     NS_DECL_NSISTREAMBUFFERACCESS
     NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM
 
     nsBufferedInputStream() : nsBufferedStream() {}
-    virtual ~nsBufferedInputStream() {}
 
     static nsresult
     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
 
     nsIInputStream* Source() { 
         return (nsIInputStream*)mStream;
     }
 
 protected:
+    virtual ~nsBufferedInputStream() {}
+
     NS_IMETHOD Fill();
     NS_IMETHOD Flush() { return NS_OK; } // no-op for input streams
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 
 class nsBufferedOutputStream : public nsBufferedStream, 
                                public nsISafeOutputStream,
@@ -95,26 +96,27 @@ class nsBufferedOutputStream : public ns
 public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSIOUTPUTSTREAM
     NS_DECL_NSISAFEOUTPUTSTREAM
     NS_DECL_NSIBUFFEREDOUTPUTSTREAM
     NS_DECL_NSISTREAMBUFFERACCESS
 
     nsBufferedOutputStream() : nsBufferedStream() {}
-    virtual ~nsBufferedOutputStream() { nsBufferedOutputStream::Close(); }
 
     static nsresult
     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
 
     nsIOutputStream* Sink() { 
         return (nsIOutputStream*)mStream;
     }
 
 protected:
+    virtual ~nsBufferedOutputStream() { nsBufferedOutputStream::Close(); }
+
     NS_IMETHOD Fill() { return NS_OK; } // no-op for output streams
 
     nsCOMPtr<nsISafeOutputStream> mSafeStream; // QI'd from mStream
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 
 #endif // nsBufferedStreams_h__
--- a/netwerk/base/src/nsFileStreams.h
+++ b/netwerk/base/src/nsFileStreams.h
@@ -129,25 +129,25 @@ public:
 
     // Overrided from nsFileStreamBase
     NS_IMETHOD Seek(int32_t aWhence, int64_t aOffset);
 
     nsFileInputStream()
       : mLineBuffer(nullptr), mIOFlags(0), mPerm(0), mCachedPosition(0)
     {}
 
+    static nsresult
+    Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
+
+protected:
     virtual ~nsFileInputStream()
     {
         Close();
     }
 
-    static nsresult
-    Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
-
-protected:
     nsAutoPtr<nsLineBuffer<char> > mLineBuffer;
 
     /**
      * The file being opened.
      */
     nsCOMPtr<nsIFile> mFile;
     /**
      * The IO flags passed to Init() for the file open.
@@ -190,16 +190,20 @@ public:
     NS_IMETHOD Tell(int64_t *aResult);
     NS_IMETHOD Available(uint64_t *aResult);
     NS_IMETHOD Read(char* aBuf, uint32_t aCount, uint32_t* aResult);
     NS_IMETHOD Seek(int32_t aWhence, int64_t aOffset);
 
     static nsresult
     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
 
+protected:
+    ~nsPartialFileInputStream()
+    { }
+
 private:
     uint64_t TruncateSize(uint64_t aSize) {
           return std::min<uint64_t>(mLength - mPosition, aSize);
     }
 
     uint64_t mStart;
     uint64_t mLength;
     uint64_t mPosition;
@@ -210,23 +214,24 @@ private:
 class nsFileOutputStream : public nsFileStreamBase,
                            public nsIFileOutputStream
 {
 public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSIFILEOUTPUTSTREAM
     NS_FORWARD_NSIOUTPUTSTREAM(nsFileStreamBase::)
 
+    static nsresult
+    Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
+
+protected:
     virtual ~nsFileOutputStream()
     {
         Close();
     }
-
-    static nsresult
-    Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 
 /**
  * A safe file output stream that overwrites the destination file only
  * once writing is complete. This protects against incomplete writes
  * due to the process or the thread being interrupted or crashed.
@@ -237,28 +242,28 @@ class nsAtomicFileOutputStream : public 
 public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSISAFEOUTPUTSTREAM
 
     nsAtomicFileOutputStream() :
         mTargetFileExists(true),
         mWriteResult(NS_OK) {}
 
-    virtual ~nsAtomicFileOutputStream()
-    {
-        Close();
-    }
-
     virtual nsresult DoOpen() MOZ_OVERRIDE;
 
     NS_IMETHODIMP Close();
     NS_IMETHODIMP Write(const char *buf, uint32_t count, uint32_t *result);
     NS_IMETHODIMP Init(nsIFile* file, int32_t ioFlags, int32_t perm, int32_t behaviorFlags);
 
 protected:
+    virtual ~nsAtomicFileOutputStream()
+    {
+        Close();
+    }
+
     nsCOMPtr<nsIFile>         mTargetFile;
     nsCOMPtr<nsIFile>         mTempFile;
 
     bool     mTargetFileExists;
     nsresult mWriteResult; // Internally set in Write()
 
 };
 
@@ -306,16 +311,17 @@ public:
     }
     NS_IMETHOD WriteSegments(nsReadSegmentFun aReader, void* aClosure,
                              uint32_t aCount, uint32_t* _retval)
     {
         return nsFileStreamBase::WriteSegments(aReader, aClosure, aCount,
                                                _retval);
     }
 
+protected:
     virtual ~nsFileStream()
     {
         Close();
     }
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 
--- a/netwerk/cache2/OldWrappers.h
+++ b/netwerk/cache2/OldWrappers.h
@@ -65,20 +65,22 @@ public:
 
   _OldCacheLoad(nsCSubstring const& aScheme,
                 nsCSubstring const& aCacheKey,
                 nsICacheEntryOpenCallback* aCallback,
                 nsIApplicationCache* aAppCache,
                 nsILoadContextInfo* aLoadInfo,
                 bool aWriteToDisk,
                 uint32_t aFlags);
-  virtual ~_OldCacheLoad();
 
   nsresult Start();
 
+protected:
+  virtual ~_OldCacheLoad();
+
 private:
   void Check();
 
   nsCOMPtr<nsIEventTarget> mCacheThread;
 
   nsCString const mScheme;
   nsCString const mCacheKey;
   nsCOMPtr<nsICacheEntryOpenCallback> mCallback;
--- a/netwerk/protocol/device/nsDeviceChannel.h
+++ b/netwerk/protocol/device/nsDeviceChannel.h
@@ -9,16 +9,18 @@
 #include "nsBaseChannel.h"
 
 class nsDeviceChannel : public nsBaseChannel
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   nsDeviceChannel();
-  ~nsDeviceChannel();
 
   nsresult Init(nsIURI* uri);
   nsresult OpenContentStream(bool aAsync,
                              nsIInputStream **aStream,
                              nsIChannel **aChannel);
+
+protected:
+  ~nsDeviceChannel();
 };
 #endif
--- a/netwerk/protocol/file/nsFileChannel.cpp
+++ b/netwerk/protocol/file/nsFileChannel.cpp
@@ -179,16 +179,24 @@ public:
 
 private:
   void OnCopyComplete();
 
   nsRefPtr<nsFileCopyEvent> mCopyEvent;
   nsCOMPtr<nsITransportEventSink> mSink;
 };
 
+namespace mozilla {
+template<>
+struct HasDangerousPublicDestructor<nsFileUploadContentStream>
+{
+  static const bool value = true;
+};
+}
+
 NS_IMPL_ISUPPORTS_INHERITED0(nsFileUploadContentStream,
                              nsBaseContentStream)
 
 NS_IMETHODIMP
 nsFileUploadContentStream::ReadSegments(nsWriteSegmentFun fun, void *closure,
                                         uint32_t count, uint32_t *result)
 {
   *result = 0;  // nothing is ever actually read from this stream
@@ -264,16 +272,20 @@ nsFileChannel::nsFileChannel(nsIURI *uri
     nsLoadFlags loadFlags = 0;
     GetLoadFlags(&loadFlags);
     SetLoadFlags(loadFlags | nsIChannel::LOAD_REPLACE);
   } else {
     SetURI(uri);
   }
 }
 
+nsFileChannel::~nsFileChannel()
+{
+}
+
 nsresult
 nsFileChannel::MakeFileInputStream(nsIFile *file,
                                    nsCOMPtr<nsIInputStream> &stream,
                                    nsCString &contentType,
                                    bool async)
 {
   // we accept that this might result in a disk hit to stat the file
   bool isDir;
--- a/netwerk/protocol/file/nsFileChannel.h
+++ b/netwerk/protocol/file/nsFileChannel.h
@@ -18,16 +18,18 @@ class nsFileChannel : public nsBaseChann
 public: 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIFILECHANNEL
   NS_DECL_NSIUPLOADCHANNEL
 
   nsFileChannel(nsIURI *uri);
 
 protected:
+  ~nsFileChannel();
+
   // Called to construct a blocking file input stream for the given file.  This
   // method also returns a best guess at the content-type for the data stream.
   // NOTE: If the channel has a type hint set, contentType will be left
   // untouched. The caller should not use it in that case.
   nsresult MakeFileInputStream(nsIFile *file, nsCOMPtr<nsIInputStream> &stream,
                                nsCString &contentType, bool async);
 
   virtual nsresult OpenContentStream(bool async, nsIInputStream **result,
--- a/netwerk/protocol/ftp/FTPChannelChild.h
+++ b/netwerk/protocol/ftp/FTPChannelChild.h
@@ -49,17 +49,16 @@ public:
   NS_DECL_NSICHILDCHANNEL
   NS_DECL_NSIDIVERTABLECHANNEL
 
   NS_IMETHOD Cancel(nsresult status);
   NS_IMETHOD Suspend();
   NS_IMETHOD Resume();
 
   FTPChannelChild(nsIURI* uri);
-  virtual ~FTPChannelChild();
 
   void AddIPDLReference();
   void ReleaseIPDLReference();
 
   NS_IMETHOD AsyncOpen(nsIStreamListener* listener, nsISupports* aContext);
 
   // Note that we handle this ourselves, overriding the nsBaseChannel
   // default behavior, in order to be e10s-friendly.
@@ -69,16 +68,18 @@ public:
                              nsIInputStream** stream,
                              nsIChannel** channel) MOZ_OVERRIDE;
 
   bool IsSuspended();
 
   void FlushedForDiversion();
 
 protected:
+  virtual ~FTPChannelChild();
+
   bool RecvOnStartRequest(const nsresult& aChannelStatus,
                           const int64_t& aContentLength,
                           const nsCString& aContentType,
                           const PRTime& aLastModified,
                           const nsCString& aEntityID,
                           const URIParams& aURI) MOZ_OVERRIDE;
   bool RecvOnDataAvailable(const nsresult& channelStatus,
                            const nsCString& data,
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -86,17 +86,16 @@ public:
     // just call the HttpBaseChannel:: impls.
     NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags);
     NS_IMETHOD GetURI(nsIURI **aURI);
     NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks);
     NS_IMETHOD GetLoadGroup(nsILoadGroup **aLoadGroup);
     NS_IMETHOD GetRequestMethod(nsACString& aMethod);
 
     nsHttpChannel();
-    virtual ~nsHttpChannel();
 
     virtual nsresult Init(nsIURI *aURI, uint32_t aCaps, nsProxyInfo *aProxyInfo,
                           uint32_t aProxyResolveFlags,
                           nsIURI *aProxyURI);
 
     // Methods HttpBaseChannel didn't implement for us or that we override.
     //
     // nsIRequest
@@ -183,16 +182,19 @@ public: /* internal necko use only */
         mChannel->mCacheEntriesToWaitFor &= mKeep;
       }
 
     private:
       nsHttpChannel* mChannel;
       uint32_t mKeep : 2;
     };
 
+protected:
+    virtual ~nsHttpChannel();
+
 private:
     typedef nsresult (nsHttpChannel::*nsContinueRedirectionFunc)(nsresult result);
 
     bool     RequestIsConditional();
     nsresult BeginConnect();
     nsresult Connect();
     nsresult ContinueConnect();
     void     SpeculativeConnect();