Bug 1028588 - Fix dangerous public destructors in libjar/ - r=aklotz
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 24 Jun 2014 22:09:14 -0400
changeset 212533 c055d3168355200ce5bfee2edfcb14ab8340497d
parent 212532 6c7eaa0fa407a5ee9eff07db48dfd55a1e65094b
child 212534 e12602a71d8ff1b01bfa440908201f75a76fb6a5
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1028588
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 1028588 - Fix dangerous public destructors in libjar/ - r=aklotz
modules/libjar/nsJAR.h
modules/libjar/nsJARChannel.cpp
modules/libjar/nsJARInputStream.h
modules/libjar/nsJARProtocolHandler.h
modules/libjar/nsJARURI.h
modules/libjar/nsZipArchive.h
modules/libjar/zipwriter/src/nsZipDataStream.h
modules/libjar/zipwriter/src/nsZipHeader.h
--- a/modules/libjar/nsJAR.h
+++ b/modules/libjar/nsJAR.h
@@ -54,20 +54,23 @@ typedef enum
  *------------------------------------------------------------------------*/
 class nsJAR : public nsIZipReader
 {
   // Allows nsJARInputStream to call the verification functions
   friend class nsJARInputStream;
   // Allows nsZipReaderCache to access mOuterZipEntry
   friend class nsZipReaderCache;
 
+  private:
+
+    virtual ~nsJAR();
+
   public:
 
     nsJAR();
-    virtual ~nsJAR();
 
     NS_DEFINE_STATIC_CID_ACCESSOR( NS_ZIPREADER_CID )
 
     NS_DECL_THREADSAFE_ISUPPORTS
 
     NS_DECL_NSIZIPREADER
 
     nsresult GetJarPath(nsACString& aResult);
@@ -131,19 +134,20 @@ class nsJAR : public nsIZipReader
  */
 class nsJARItem : public nsIZipEntry
 {
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIZIPENTRY
 
     nsJARItem(nsZipItem* aZipItem);
+
+private:
     virtual ~nsJARItem() {}
 
-private:
     uint32_t     mSize;             /* size in original file */
     uint32_t     mRealsize;         /* inflated size */
     uint32_t     mCrc32;
     PRTime       mLastModTime;
     uint16_t     mCompression;
     uint32_t     mPermissions;
     bool mIsDirectory;
     bool mIsSynthetic;
@@ -183,24 +187,25 @@ class nsZipReaderCache : public nsIZipRe
                          public nsSupportsWeakReference
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIZIPREADERCACHE
   NS_DECL_NSIOBSERVER
 
   nsZipReaderCache();
-  virtual ~nsZipReaderCache();
 
   nsresult ReleaseZip(nsJAR* reader);
 
   typedef nsRefPtrHashtable<nsCStringHashKey, nsJAR> ZipsHashtable;
 
 protected:
 
+  virtual ~nsZipReaderCache();
+
   mozilla::Mutex        mLock;
   uint32_t              mCacheSize;
   ZipsHashtable         mZips;
 
 #ifdef ZIP_CACHE_HIT_RATE
   uint32_t              mZipCacheLookups;
   uint32_t              mZipCacheHits;
   uint32_t              mZipCacheFlushes;
--- a/modules/libjar/nsJARChannel.cpp
+++ b/modules/libjar/nsJARChannel.cpp
@@ -77,30 +77,30 @@ public:
 #ifdef DEBUG
             nsresult rv =
 #endif
                 fullJarURI->GetAsciiSpec(mJarDirSpec);
             NS_ASSERTION(NS_SUCCEEDED(rv), "this shouldn't fail");
         }
     }
 
-    virtual ~nsJARInputThunk()
-    {
-        Close();
-    }
-
     int64_t GetContentLength()
     {
         return mContentLength;
     }
 
     nsresult Init();
 
 private:
 
+    virtual ~nsJARInputThunk()
+    {
+        Close();
+    }
+
     bool                        mUsingJarCache;
     nsCOMPtr<nsIZipReader>      mJarReader;
     nsCString                   mJarDirSpec;
     nsCOMPtr<nsIInputStream>    mJarStream;
     nsCString                   mJarEntry;
     int64_t                     mContentLength;
 };
 
--- a/modules/libjar/nsJARInputStream.h
+++ b/modules/libjar/nsJARInputStream.h
@@ -22,29 +22,29 @@ class nsJARInputStream MOZ_FINAL : publi
   public:
     nsJARInputStream() : 
         mOutSize(0), mInCrc(0), mOutCrc(0), mCurPos(0),
         mMode(MODE_NOTINITED)
     { 
       memset(&mZs, 0, sizeof(z_stream));
     }
 
-    ~nsJARInputStream() { Close(); }
-
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIINPUTSTREAM
    
     // takes ownership of |fd|, even on failure
     nsresult InitFile(nsJAR *aJar, nsZipItem *item);
 
     nsresult InitDirectory(nsJAR *aJar,
                            const nsACString& aJarDirSpec,
                            const char* aDir);
   
   private:
+    ~nsJARInputStream() { Close(); }
+
     nsRefPtr<nsZipHandle>  mFd;         // handle for reading
     uint32_t               mOutSize;    // inflated size 
     uint32_t               mInCrc;      // CRC as provided by the zipentry
     uint32_t               mOutCrc;     // CRC as calculated by me
     z_stream               mZs;         // zip data structure
 
     /* For directory reading */
     nsRefPtr<nsJAR>        mJar;        // string reference to zipreader
--- a/modules/libjar/nsJARProtocolHandler.h
+++ b/modules/libjar/nsJARProtocolHandler.h
@@ -28,33 +28,34 @@ class nsJARProtocolHandler : public nsIJ
 
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIPROTOCOLHANDLER
     NS_DECL_NSIJARPROTOCOLHANDLER
 
     // nsJARProtocolHandler methods:
     nsJARProtocolHandler();
-    virtual ~nsJARProtocolHandler();
 
     static nsJARProtocolHandler *GetSingleton();
 
     nsresult Init();
 
     // returns non addref'ed pointer.  
     nsIMIMEService    *MimeService();
     nsIZipReaderCache *JarCache() { return mJARCache; }
 
     bool IsMainProcess() const { return mIsMainProcess; }
 
     bool RemoteOpenFileInProgress(nsIHashable *aRemoteFile,
                                   nsIRemoteOpenFileListener *aListener);
     void RemoteOpenFileComplete(nsIHashable *aRemoteFile, nsresult aStatus);
 
 protected:
+    virtual ~nsJARProtocolHandler();
+
     nsCOMPtr<nsIZipReaderCache> mJARCache;
     nsCOMPtr<nsIMIMEService> mMimeService;
 
     // Holds lists of RemoteOpenFileChild (not including the 1st) that have
     // requested the same file from parent.
     nsClassHashtable<nsHashableHashKey, RemoteFileListenerArray>
         mRemoteFileListeners;
 
--- a/modules/libjar/nsJARURI.h
+++ b/modules/libjar/nsJARURI.h
@@ -47,27 +47,28 @@ public:
     NS_DECL_NSICLASSINFO
     NS_DECL_NSINESTEDURI
     NS_DECL_NSIIPCSERIALIZABLEURI
 
     NS_DECLARE_STATIC_IID_ACCESSOR(NS_THIS_JARURI_IMPL_CID)
 
     // nsJARURI
     nsJARURI();
-    virtual ~nsJARURI();
    
     nsresult Init(const char *charsetHint);
     nsresult FormatSpec(const nsACString &entryPath, nsACString &result,
                         bool aIncludeScheme = true);
     nsresult CreateEntryURL(const nsACString& entryFilename,
                             const char* charset,
                             nsIURL** url);
     nsresult SetSpecWithBase(const nsACString& aSpec, nsIURI* aBaseURL);
 
 protected:
+    virtual ~nsJARURI();
+
     // enum used in a few places to specify how .ref attribute should be handled
     enum RefHandlingEnum {
         eIgnoreRef,
         eHonorRef
     };
 
     // Helper to share code between Equals methods.
     virtual nsresult EqualsInternal(nsIURI* other,
--- a/modules/libjar/nsZipArchive.h
+++ b/modules/libjar/nsZipArchive.h
@@ -90,23 +90,23 @@ class nsZipHandle;
 /** 
  * nsZipArchive -- a class for reading the PKZIP file format.
  *
  */
 class nsZipArchive 
 {
   friend class nsZipFind;
 
+  /** destructing the object closes the archive */
+  ~nsZipArchive();
+
 public:
   /** constructing does not open the archive. See OpenArchive() */
   nsZipArchive();
 
-  /** destructing the object closes the archive */
-  ~nsZipArchive();
-
   /** 
    * OpenArchive 
    * 
    * It's an error to call this more than once on the same nsZipArchive
    * object. If we were allowed to use exceptions this would have been 
    * part of the constructor 
    *
    * @param   aZipHandle  The nsZipHandle used to access the zip
--- a/modules/libjar/zipwriter/src/nsZipDataStream.h
+++ b/modules/libjar/zipwriter/src/nsZipDataStream.h
@@ -25,16 +25,18 @@ public:
 
     nsresult Init(nsZipWriter *aWriter, nsIOutputStream *aStream,
                   nsZipHeader *aHeader, int32_t aCompression);
 
     nsresult ReadStream(nsIInputStream *aStream);
 
 private:
 
+    ~nsZipDataStream() {}
+
     nsCOMPtr<nsIStreamListener> mOutput;
     nsCOMPtr<nsIOutputStream> mStream;
     nsRefPtr<nsZipWriter> mWriter;
     nsRefPtr<nsZipHeader> mHeader;
 
     nsresult CompleteEntry();
     nsresult ProcessData(nsIRequest *aRequest, nsISupports *aContext,
                          char *aBuffer, uint64_t aOffset, uint32_t aCount);
--- a/modules/libjar/zipwriter/src/nsZipHeader.h
+++ b/modules/libjar/zipwriter/src/nsZipHeader.h
@@ -20,16 +20,22 @@
 #define PERMISSIONS_FILE 0644
 #define PERMISSIONS_DIR 0755
 
 // Combine file type attributes with unix style permissions
 #define ZIP_ATTRS(p, a) ((p & 0xfff) << 16) | a
 
 class nsZipHeader MOZ_FINAL : public nsIZipEntry
 {
+    ~nsZipHeader()
+    {
+        mExtraField = nullptr;
+        mLocalExtraField = nullptr;
+    }
+
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIZIPENTRY
 
     nsZipHeader() :
         mCRC(0),
         mCSize(0),
         mUSize(0),
@@ -47,22 +53,16 @@ public:
         mIAttr(0),
         mInited(false),
         mWriteOnClose(false),
         mExtraField(nullptr),
         mLocalExtraField(nullptr)
     {
     }
 
-    ~nsZipHeader()
-    {
-        mExtraField = nullptr;
-        mLocalExtraField = nullptr;
-    }
-
     uint32_t mCRC;
     uint32_t mCSize;
     uint32_t mUSize;
     uint32_t mEAttr;
     uint32_t mOffset;
     uint32_t mFieldLength;
     uint32_t mLocalFieldLength;
     uint16_t mVersionMade;