Bug 1395246: nullcheck DataChannel SendPacket calls, add some diagnostics r=drno

This commit is contained in:
Randell Jesup 2018-06-07 15:26:25 -04:00
parent e5398fd8f8
commit c0b25e1706
2 changed files with 17 additions and 3 deletions

View file

@ -318,6 +318,9 @@ DataChannelConnection::DataChannelConnection(DataConnectionListener *listener,
mPendingType = PENDING_NONE; mPendingType = PENDING_NONE;
LOG(("Constructor DataChannelConnection=%p, listener=%p", this, mListener.get())); LOG(("Constructor DataChannelConnection=%p, listener=%p", this, mListener.get()));
mInternalIOThread = nullptr; mInternalIOThread = nullptr;
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
mShutdown = false;
#endif
} }
DataChannelConnection::~DataChannelConnection() DataChannelConnection::~DataChannelConnection()
@ -395,6 +398,9 @@ void DataChannelConnection::DestroyOnSTS(struct socket *aMasterSocket,
usrsctp_deregister_address(static_cast<void *>(this)); usrsctp_deregister_address(static_cast<void *>(this));
LOG(("Deregistered %p from the SCTP stack.", static_cast<void *>(this))); LOG(("Deregistered %p from the SCTP stack.", static_cast<void *>(this)));
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
mShutdown = true;
#endif
disconnect_all(); disconnect_all();
@ -831,7 +837,10 @@ int
DataChannelConnection::SendPacket(unsigned char data[], size_t len, bool release) DataChannelConnection::SendPacket(unsigned char data[], size_t len, bool release)
{ {
//LOG(("%p: SCTP/DTLS sent %ld bytes", this, len)); //LOG(("%p: SCTP/DTLS sent %ld bytes", this, len));
int res = mTransportFlow->SendPacket(data, len) < 0 ? 1 : 0; int res = 0;
if (mTransportFlow) {
res = mTransportFlow->SendPacket(data, len) < 0 ? 1 : 0;
}
if (release) if (release)
delete [] data; delete [] data;
return res; return res;
@ -844,6 +853,7 @@ DataChannelConnection::SctpDtlsOutput(void *addr, void *buffer, size_t length,
{ {
DataChannelConnection *peer = static_cast<DataChannelConnection *>(addr); DataChannelConnection *peer = static_cast<DataChannelConnection *>(addr);
int res; int res;
MOZ_DIAGNOSTIC_ASSERT(!peer->mShutdown);
if (MOZ_LOG_TEST(gSCTPLog, LogLevel::Debug)) { if (MOZ_LOG_TEST(gSCTPLog, LogLevel::Debug)) {
char *buf; char *buf;

View file

@ -139,7 +139,7 @@ public:
virtual void NotifyDataChannel(already_AddRefed<DataChannel> channel) = 0; virtual void NotifyDataChannel(already_AddRefed<DataChannel> channel) = 0;
}; };
explicit DataChannelConnection(DataConnectionListener *listener, DataChannelConnection(DataConnectionListener *listener,
nsIEventTarget *aTarget); nsIEventTarget *aTarget);
bool Init(unsigned short aPort, uint16_t aNumStreams, bool aMaxMessageSizeSet, bool Init(unsigned short aPort, uint16_t aNumStreams, bool aMaxMessageSizeSet,
@ -342,6 +342,10 @@ private:
nsCOMPtr<nsIThread> mInternalIOThread; nsCOMPtr<nsIThread> mInternalIOThread;
uint8_t mPendingType; uint8_t mPendingType;
nsCString mRecvBuffer; nsCString mRecvBuffer;
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
bool mShutdown;
#endif
}; };
#define ENSURE_DATACONNECTION \ #define ENSURE_DATACONNECTION \