Bug 1027251 - Fix or whitelist dangerous public destructors in media/mtransport - r=abr
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 20 Jun 2014 07:08:24 -0400
changeset 189810 a61c4689026f1786499961c8cfc3512324b605e2
parent 189809 77f59b3856545de416d405975945bf8fb147e775
child 189811 0d16701f4e3fbdd7369500aa8e756b41f02e60ec
push id7383
push userttaubert@mozilla.com
push dateFri, 20 Jun 2014 16:49:43 +0000
treeherderfx-team@b0b5ad421d67 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersabr
bugs1027251
milestone33.0a1
Bug 1027251 - Fix or whitelist dangerous public destructors in media/mtransport - r=abr
media/mtransport/databuffer.h
media/mtransport/dtlsidentity.h
media/mtransport/nr_socket_prsock.h
media/mtransport/nricectx.h
media/mtransport/nricemediastream.h
media/mtransport/nriceresolver.h
media/mtransport/test/buffered_stun_socket_unittest.cpp
media/mtransport/test/runnable_utils_unittest.cpp
media/mtransport/transportlayerdtls.h
--- a/media/mtransport/databuffer.h
+++ b/media/mtransport/databuffer.h
@@ -10,16 +10,24 @@
 #define databuffer_h__
 #include <algorithm>
 #include <mozilla/Scoped.h>
 #include <m_cpp_utils.h>
 #include <nsISupportsImpl.h>
 
 namespace mozilla {
 
+class DataBuffer;
+
+template<>
+struct HasDangerousPublicDestructor<DataBuffer>
+{
+  static const bool value = true;
+};
+
 class DataBuffer {
  public:
   DataBuffer() : data_(nullptr), len_(0) {}
   DataBuffer(const uint8_t *data, size_t len) {
     Assign(data, len);
   }
 
   void Assign(const uint8_t *data, size_t len) {
--- a/media/mtransport/dtlsidentity.h
+++ b/media/mtransport/dtlsidentity.h
@@ -14,19 +14,19 @@
 #include "ScopedNSSTypes.h"
 
 // All code in this module requires NSS to be live.
 // Callers must initialize NSS and implement the nsNSSShutdownObject
 // protocol.
 namespace mozilla {
 
 class DtlsIdentity {
- public:
   ~DtlsIdentity();
 
+ public:
   // Generate an identity with a random name.
   static TemporaryRef<DtlsIdentity> Generate();
 
   // Note: the following two functions just provide access. They
   // do not transfer ownership. If you want a pointer that lasts
   // past the lifetime of the DtlsIdentity, you must make
   // a copy yourself.
   CERTCertificate *cert() { return cert_; }
--- a/media/mtransport/nr_socket_prsock.h
+++ b/media/mtransport/nr_socket_prsock.h
@@ -177,16 +177,17 @@ struct nr_udp_message {
   }
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nr_udp_message);
 
   PRNetAddr from;
   nsAutoPtr<DataBuffer> data;
 
 private:
+  ~nr_udp_message() {}
   DISALLOW_COPY_ASSIGN(nr_udp_message);
 };
 
 class NrSocketIpc : public NrSocketBase,
                     public nsIUDPSocketInternal {
 public:
 
   enum NrSocketIpcState {
--- a/media/mtransport/nricectx.h
+++ b/media/mtransport/nricectx.h
@@ -186,18 +186,16 @@ class NrIceCtx {
 
   enum Controlling { ICE_CONTROLLING,
                      ICE_CONTROLLED
   };
 
   static RefPtr<NrIceCtx> Create(const std::string& name,
                                  bool offerer,
                                  bool set_interface_priorities = true);
-  virtual ~NrIceCtx();
-
   nr_ice_ctx *ctx() { return ctx_; }
   nr_ice_peer_ctx *peer() { return peer_; }
 
   // Testing only.
   void destroy_peer_ctx();
 
   // Create a media stream
   RefPtr<NrIceMediaStream> CreateStream(const std::string& name,
@@ -276,16 +274,18 @@ class NrIceCtx {
     peer_(nullptr),
     ice_handler_vtbl_(nullptr),
     ice_handler_(nullptr),
     trickle_(true) {
     // XXX: offerer_ will be used eventually;  placate clang in the meantime.
     (void)offerer_;
   }
 
+  virtual ~NrIceCtx();
+
   DISALLOW_COPY_ASSIGN(NrIceCtx);
 
   // Callbacks for nICEr
   static void initialized_cb(NR_SOCKET s, int h, void *arg);  // ICE initialized
 
   // Handler implementation
   static int select_pair(void *obj,nr_ice_media_stream *stream,
                          int component_id, nr_ice_cand_pair **potentials,
--- a/media/mtransport/nricemediastream.h
+++ b/media/mtransport/nricemediastream.h
@@ -120,18 +120,16 @@ class NrIceOpaque {
   virtual ~NrIceOpaque() {}
 };
 
 class NrIceMediaStream {
  public:
   static RefPtr<NrIceMediaStream> Create(NrIceCtx *ctx,
                                          const std::string& name,
                                          int components);
-  ~NrIceMediaStream();
-
   enum State { ICE_CONNECTING, ICE_OPEN, ICE_CLOSED};
 
   State state() const { return state_; }
 
   // The name of the stream
   const std::string& name() const { return name_; }
 
   // Get all the candidates
@@ -201,16 +199,18 @@ class NrIceMediaStream {
                    int components) :
       state_(ICE_CONNECTING),
       ctx_(ctx),
       name_(name),
       components_(components),
       stream_(nullptr),
       opaque_(nullptr) {}
 
+  ~NrIceMediaStream();
+
   DISALLOW_COPY_ASSIGN(NrIceMediaStream);
 
   State state_;
   NrIceCtx *ctx_;
   const std::string name_;
   const int components_;
   nr_ice_media_stream *stream_;
   ScopedDeletePtr<NrIceOpaque> opaque_;
--- a/media/mtransport/nriceresolver.h
+++ b/media/mtransport/nriceresolver.h
@@ -56,19 +56,19 @@ typedef struct nr_resolver_ nr_resolver;
 typedef struct nr_resolver_vtbl_ nr_resolver_vtbl;
 typedef struct nr_transport_addr_ nr_transport_addr;
 typedef struct nr_resolver_resource_ nr_resolver_resource;
 
 namespace mozilla {
 
 class NrIceResolver
 {
+  ~NrIceResolver();
  public:
   NrIceResolver();
-  ~NrIceResolver();
 
   nsresult Init();
   nr_resolver *AllocateResolver();
   void DestroyResolver();
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceResolver)
 
  private:
   // Implementations of vtbl functions
--- a/media/mtransport/test/buffered_stun_socket_unittest.cpp
+++ b/media/mtransport/test/buffered_stun_socket_unittest.cpp
@@ -37,16 +37,26 @@ MtransportTestUtils *test_utils;
 static uint8_t kStunMessage[] = {
   0x00, 0x01, 0x00, 0x08, 0x21, 0x12, 0xa4, 0x42,
   0x9b, 0x90, 0xbe, 0x2c, 0xae, 0x1a, 0x0c, 0xa8,
   0xa0, 0xd6, 0x8b, 0x08, 0x80, 0x28, 0x00, 0x04,
   0xdb, 0x35, 0x5f, 0xaa
 };
 static size_t kStunMessageLen = sizeof(kStunMessage);
 
+class DummySocket;
+
+namespace mozilla {
+template<>
+struct HasDangerousPublicDestructor<DummySocket>
+{
+  static const bool value = true;
+};
+}
+
 class DummySocket : public NrSocketBase {
  public:
   DummySocket()
       : writable_(UINT_MAX),
         write_buffer_(nullptr),
         readable_(UINT_MAX),
         read_buffer_(nullptr),
         cb_(nullptr),
--- a/media/mtransport/test/runnable_utils_unittest.cpp
+++ b/media/mtransport/test/runnable_utils_unittest.cpp
@@ -33,22 +33,22 @@
 #include "gtest_utils.h"
 
 using namespace mozilla;
 MtransportTestUtils *test_utils;
 
 namespace {
 
 class Destructor {
- public:
-  Destructor(bool* destroyed) : destroyed_(destroyed) {}
   ~Destructor() {
     std::cerr << "Destructor called" << std::endl;
     *destroyed_ = true;
   }
+ public:
+  Destructor(bool* destroyed) : destroyed_(destroyed) {}
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Destructor)
 
  private:
   bool *destroyed_;
 };
 
 class TargetClass {
--- a/media/mtransport/transportlayerdtls.h
+++ b/media/mtransport/transportlayerdtls.h
@@ -115,16 +115,17 @@ class TransportLayerDtls : public Transp
 
     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VerificationDigest)
 
     std::string algorithm_;
     size_t len_;
     unsigned char value_[kMaxDigestLength];
 
    private:
+    ~VerificationDigest() {}
     DISALLOW_COPY_ASSIGN(VerificationDigest);
   };
 
 
   bool Setup();
   void Handshake();
 
   static SECStatus GetClientAuthDataHook(void *arg, PRFileDesc *fd,