Skip to content

Commit

Permalink
Bug 1333142 - audit asyncopen2 impls for callback release on failure …
Browse files Browse the repository at this point in the history
…r=dragana
  • Loading branch information
mcmanus committed Feb 8, 2017
1 parent 5d98b48 commit d986482
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 9 deletions.
17 changes: 14 additions & 3 deletions image/decoders/icon/mac/nsIconChannelCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,17 @@

nsCOMPtr<nsIInputStream> inStream;
nsresult rv = MakeInputStream(getter_AddRefs(inStream), true);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}

// Init our stream pump
rv = mPump->Init(inStream, int64_t(-1), int64_t(-1), 0, 0, false);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}

rv = mPump->AsyncRead(this, ctxt);
if (NS_SUCCEEDED(rv)) {
Expand All @@ -244,6 +250,8 @@
if (mLoadGroup) {
mLoadGroup->AddRequest(this, nullptr);
}
} else {
mCallbacks = nullptr;
}

return rv;
Expand All @@ -254,7 +262,10 @@
{
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}
return AsyncOpen(listener, nullptr);
}

Expand Down
10 changes: 9 additions & 1 deletion image/decoders/icon/win/nsIconChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@ nsIconChannel::AsyncOpen(nsIStreamListener* aListener,
nsCOMPtr<nsIInputStream> inStream;
nsresult rv = MakeInputStream(getter_AddRefs(inStream), true);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}

// Init our streampump
rv = mPump->Init(inStream, int64_t(-1), int64_t(-1), 0, 0, false);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}

Expand All @@ -262,7 +264,10 @@ nsIconChannel::AsyncOpen(nsIStreamListener* aListener,
if (mLoadGroup) {
mLoadGroup->AddRequest(this, nullptr);
}
} else {
mCallbacks = nullptr;
}

return rv;
}

Expand All @@ -271,7 +276,10 @@ nsIconChannel::AsyncOpen2(nsIStreamListener* aListener)
{
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}
return AsyncOpen(listener, nullptr);
}

Expand Down
21 changes: 20 additions & 1 deletion modules/libjar/nsJARChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
mIsPending = false;
mListenerContext = nullptr;
mListener = nullptr;
mCallbacks = nullptr;
mProgressSink = nullptr;
return rv;
}

Expand All @@ -788,6 +790,11 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
// Check preferences to see if all remote jar support should be disabled
if (mBlockRemoteFiles) {
mIsUnsafe = true;
mIsPending = false;
mListenerContext = nullptr;
mListener = nullptr;
mCallbacks = nullptr;
mProgressSink = nullptr;
return NS_ERROR_UNSAFE_CONTENT_TYPE;
}

Expand All @@ -811,6 +818,8 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
mIsPending = false;
mListenerContext = nullptr;
mListener = nullptr;
mCallbacks = nullptr;
mProgressSink = nullptr;
return rv;
}
if (mLoadInfo && mLoadInfo->GetEnforceSecurity()) {
Expand All @@ -828,6 +837,8 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
mIsPending = false;
mListenerContext = nullptr;
mListener = nullptr;
mCallbacks = nullptr;
mProgressSink = nullptr;
return rv;
}

Expand All @@ -844,7 +855,15 @@ nsJARChannel::AsyncOpen2(nsIStreamListener *aListener)
{
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mIsPending = false;
mListenerContext = nullptr;
mListener = nullptr;
mCallbacks = nullptr;
mProgressSink = nullptr;
return rv;
}

return AsyncOpen(listener, nullptr);
}

Expand Down
5 changes: 4 additions & 1 deletion netwerk/base/nsBaseChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,10 @@ nsBaseChannel::AsyncOpen2(nsIStreamListener *aListener)
{
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}
return AsyncOpen(listener, nullptr);
}

Expand Down
6 changes: 5 additions & 1 deletion netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ WyciwygChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aConte

mozilla::dom::TabChild* tabChild = GetTabChild(this);
if (MissingRequiredTabChild(tabChild, "wyciwyg")) {
mCallbacks = nullptr;
return NS_ERROR_ILLEGAL_VALUE;
}

Expand All @@ -665,7 +666,10 @@ WyciwygChannelChild::AsyncOpen2(nsIStreamListener *aListener)
{
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}
return AsyncOpen(listener, nullptr);
}

Expand Down
7 changes: 6 additions & 1 deletion netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ nsWyciwygChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
if (NS_FAILED(rv)) {
LOG(("nsWyciwygChannel::OpenCacheEntry failed [rv=%x]\n", rv));
mIsPending = false;
mCallbacks = nullptr;
return rv;
}

Expand All @@ -466,7 +467,11 @@ nsWyciwygChannel::AsyncOpen2(nsIStreamListener *aListener)
{
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mIsPending = false;
mCallbacks = nullptr;
return rv;
}
return AsyncOpen(listener, nullptr);
}

Expand Down
5 changes: 4 additions & 1 deletion uriloader/exthandler/nsExternalProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen2(nsIStreamListener *aListener)
{
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;
}
return AsyncOpen(listener, nullptr);
}

Expand Down

0 comments on commit d986482

Please sign in to comment.