gecko/netwerk/protocol/http/NullHttpTransaction.cpp
Patrick McManus fdaefb68d6 bug 1116867 - make nsIProgressEventSink and nsITransportEventSink safely scriptable r=mayhemer r=bz
These scriptable interfaces use uint_64 arguments with sentinel values
of UINT64_MAX. However, UINT64_MAX exceeds MAX_SAFE_INTEGER and cannot
be gatewayed to/from javascript - so they cannot be used
correctly. Change them to use signed 64 bit numbers and -1 as the
sentinnel. C++ implementations ought to be enough to audit as the
special value could never be used correctly in JS anyhow - also
audited OnProgressChange() uses for downstream use of this data.
---
 dom/base/nsXMLHttpRequest.cpp                      | 19 +++++++----
 dom/base/nsXMLHttpRequest.h                        | 10 +++---
 dom/plugins/base/nsPluginStreamListenerPeer.cpp    |  4 +--
 .../webbrowserpersist/nsWebBrowserPersist.cpp      | 14 ++++----
 image/src/imgLoader.cpp                            |  4 +--
 modules/libjar/nsJARChannel.cpp                    |  3 +-
 netwerk/base/public/nsIProgressEventSink.idl       |  8 ++---
 netwerk/base/public/nsITransport.idl               |  8 ++---
 netwerk/base/public/nsNetUtil.h                    | 24 ++++++++++++++
 netwerk/base/src/Dashboard.cpp                     |  2 +-
 netwerk/base/src/nsBaseChannel.cpp                 | 12 +++----
 netwerk/base/src/nsIncrementalDownload.cpp         |  4 +--
 netwerk/base/src/nsSocketTransport2.cpp            |  5 +--
 netwerk/base/src/nsStreamTransportService.cpp      | 38 +++++++++++++---------
 netwerk/base/src/nsTransportUtils.cpp              | 12 +++----
 netwerk/protocol/file/nsFileChannel.cpp            |  8 +++--
 netwerk/protocol/ftp/nsFtpConnectionThread.cpp     |  4 +--
 netwerk/protocol/http/Http2Push.cpp                |  2 +-
 netwerk/protocol/http/Http2Session.cpp             |  2 +-
 netwerk/protocol/http/HttpChannelChild.cpp         | 31 +++++++++---------
 netwerk/protocol/http/HttpChannelChild.h           |  6 ++--
 netwerk/protocol/http/HttpChannelParent.cpp        |  4 +--
 netwerk/protocol/http/HttpChannelParent.h          |  4 +--
 netwerk/protocol/http/NullHttpTransaction.cpp      |  2 +-
 netwerk/protocol/http/PHttpChannel.ipdl            |  2 +-
 netwerk/protocol/http/SpdyPush31.cpp               |  2 +-
 netwerk/protocol/http/SpdySession31.cpp            |  2 +-
 netwerk/protocol/http/TunnelUtils.cpp              |  2 +-
 netwerk/protocol/http/nsAHttpTransaction.h         |  4 +--
 netwerk/protocol/http/nsHttpChannel.cpp            | 30 +++++++++++------
 netwerk/protocol/http/nsHttpConnection.cpp         |  4 +--
 netwerk/protocol/http/nsHttpConnectionMgr.cpp      |  4 +--
 netwerk/protocol/http/nsHttpPipeline.cpp           |  4 +--
 netwerk/protocol/http/nsHttpPipeline.h             |  6 ++--
 netwerk/protocol/http/nsHttpResponseHead.cpp       |  2 +-
 netwerk/protocol/http/nsHttpResponseHead.h         |  2 +-
 netwerk/protocol/http/nsHttpTransaction.cpp        | 32 +++++++++---------
 netwerk/protocol/http/nsHttpTransaction.h          |  2 +-
 netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp   |  2 +-
 netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp      |  3 +-
 netwerk/test/TestIncrementalDownload.cpp           |  7 ++--
 uriloader/base/nsDocLoader.cpp                     | 14 ++++----
 42 files changed, 203 insertions(+), 151 deletions(-)
2015-01-08 14:48:52 -05:00

321 lines
8.6 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// HttpLog.h should generally be included first
#include "HttpLog.h"
#include "nsHttp.h"
#include "NullHttpTransaction.h"
#include "nsHttpHandler.h"
#include "nsHttpRequestHead.h"
#include "nsIHttpActivityObserver.h"
#include "NullHttpChannel.h"
namespace mozilla {
namespace net {
class CallObserveActivity MOZ_FINAL : public nsIRunnable
{
~CallObserveActivity()
{
}
public:
NS_DECL_THREADSAFE_ISUPPORTS
CallObserveActivity(nsIHttpActivityObserver *aActivityDistributor,
const nsCString &aHost,
int32_t aPort,
bool aEndToEndSSL,
uint32_t aActivityType,
uint32_t aActivitySubtype,
PRTime aTimestamp,
uint64_t aExtraSizeData,
const nsACString &aExtraStringData)
: mActivityDistributor(aActivityDistributor)
, mHost(aHost)
, mPort(aPort)
, mEndToEndSSL(aEndToEndSSL)
, mActivityType(aActivityType)
, mActivitySubtype(aActivitySubtype)
, mTimestamp(aTimestamp)
, mExtraSizeData(aExtraSizeData)
, mExtraStringData(aExtraStringData)
{
}
NS_IMETHOD Run() MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIURI> uri;
nsAutoCString port(NS_LITERAL_CSTRING(""));
if (mPort != -1 && ((mEndToEndSSL && mPort != 443) ||
(!mEndToEndSSL && mPort != 80))) {
port.AppendInt(mPort);
}
nsresult rv = NS_NewURI(getter_AddRefs(uri),
(mEndToEndSSL ? NS_LITERAL_CSTRING("https://")
: NS_LITERAL_CSTRING("http://") ) + mHost + port);
if (NS_FAILED(rv)) {
return NS_OK;
}
nsRefPtr<NullHttpChannel> channel = new NullHttpChannel();
channel->Init(uri, 0, nullptr, 0, nullptr);
mActivityDistributor->ObserveActivity(
nsCOMPtr<nsISupports>(do_QueryObject(channel)),
mActivityType,
mActivitySubtype,
mTimestamp,
mExtraSizeData,
mExtraStringData);
return NS_OK;
}
private:
nsCOMPtr<nsIHttpActivityObserver> mActivityDistributor;
nsCString mHost;
int32_t mPort;
bool mEndToEndSSL;
uint32_t mActivityType;
uint32_t mActivitySubtype;
PRTime mTimestamp;
uint64_t mExtraSizeData;
nsCString mExtraStringData;
};
NS_IMPL_ISUPPORTS(CallObserveActivity, nsIRunnable)
NS_IMPL_ISUPPORTS(NullHttpTransaction, NullHttpTransaction, nsISupportsWeakReference)
NullHttpTransaction::NullHttpTransaction(nsHttpConnectionInfo *ci,
nsIInterfaceRequestor *callbacks,
uint32_t caps)
: mStatus(NS_OK)
, mCaps(caps | NS_HTTP_ALLOW_KEEPALIVE)
, mCapsToClear(0)
, mRequestHead(nullptr)
, mIsDone(false)
, mCallbacks(callbacks)
, mConnectionInfo(ci)
{
nsresult rv;
mActivityDistributor = do_GetService(NS_HTTPACTIVITYDISTRIBUTOR_CONTRACTID,
&rv);
if (NS_FAILED(rv)) {
return;
}
bool activityDistributorActive;
rv = mActivityDistributor->GetIsActive(&activityDistributorActive);
if (NS_SUCCEEDED(rv) && activityDistributorActive) {
// There are some observers registered at activity distributor.
LOG(("NulHttpTransaction::NullHttpTransaction() "
"mActivityDistributor is active "
"[this=%p, %s]", this, ci->GetHost().get()));
} else {
// There is no observer, so don't use it.
mActivityDistributor = nullptr;
}
}
NullHttpTransaction::~NullHttpTransaction()
{
mCallbacks = nullptr;
delete mRequestHead;
}
void
NullHttpTransaction::SetConnection(nsAHttpConnection *conn)
{
mConnection = conn;
}
nsAHttpConnection *
NullHttpTransaction::Connection()
{
return mConnection.get();
}
void
NullHttpTransaction::GetSecurityCallbacks(nsIInterfaceRequestor **outCB)
{
nsCOMPtr<nsIInterfaceRequestor> copyCB(mCallbacks);
*outCB = copyCB.forget().take();
}
void
NullHttpTransaction::OnTransportStatus(nsITransport* transport,
nsresult status, int64_t progress)
{
if (mActivityDistributor) {
NS_DispatchToMainThread(new CallObserveActivity(mActivityDistributor,
mConnectionInfo->GetHost(),
mConnectionInfo->Port(),
mConnectionInfo->EndToEndSSL(),
NS_HTTP_ACTIVITY_TYPE_SOCKET_TRANSPORT,
static_cast<uint32_t>(status),
PR_Now(),
progress,
EmptyCString()));
}
}
bool
NullHttpTransaction::IsDone()
{
return mIsDone;
}
nsresult
NullHttpTransaction::Status()
{
return mStatus;
}
uint32_t
NullHttpTransaction::Caps()
{
return mCaps & ~mCapsToClear;
}
void
NullHttpTransaction::SetDNSWasRefreshed()
{
MOZ_ASSERT(NS_IsMainThread(), "SetDNSWasRefreshed on main thread only!");
mCapsToClear |= NS_HTTP_REFRESH_DNS;
}
uint64_t
NullHttpTransaction::Available()
{
return 0;
}
nsresult
NullHttpTransaction::ReadSegments(nsAHttpSegmentReader *reader,
uint32_t count, uint32_t *countRead)
{
*countRead = 0;
mIsDone = true;
return NS_BASE_STREAM_CLOSED;
}
nsresult
NullHttpTransaction::WriteSegments(nsAHttpSegmentWriter *writer,
uint32_t count, uint32_t *countWritten)
{
*countWritten = 0;
return NS_BASE_STREAM_CLOSED;
}
uint32_t
NullHttpTransaction::Http1xTransactionCount()
{
return 0;
}
nsHttpRequestHead *
NullHttpTransaction::RequestHead()
{
// We suport a requesthead at all so that a CONNECT tunnel transaction
// can obtain a Host header from it, but we lazy-popualate that header.
if (!mRequestHead) {
mRequestHead = new nsHttpRequestHead();
nsAutoCString hostHeader;
nsCString host(mConnectionInfo->GetHost());
nsresult rv = nsHttpHandler::GenerateHostPort(host,
mConnectionInfo->Port(),
hostHeader);
if (NS_SUCCEEDED(rv)) {
mRequestHead->SetHeader(nsHttp::Host, hostHeader);
if (mActivityDistributor) {
// Report request headers.
nsCString reqHeaderBuf;
mRequestHead->Flatten(reqHeaderBuf, false);
NS_DispatchToMainThread(new CallObserveActivity(mActivityDistributor,
mConnectionInfo->GetHost(),
mConnectionInfo->Port(),
mConnectionInfo->EndToEndSSL(),
NS_HTTP_ACTIVITY_TYPE_HTTP_TRANSACTION,
NS_HTTP_ACTIVITY_SUBTYPE_REQUEST_HEADER,
PR_Now(), 0, reqHeaderBuf));
}
}
// CONNECT tunnels may also want Proxy-Authorization but that is a lot
// harder to determine, so for now we will let those connections fail in
// the NullHttpTransaction and let them be retried from the pending queue
// with a bound transaction
}
return mRequestHead;
}
nsresult
NullHttpTransaction::TakeSubTransactions(
nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void
NullHttpTransaction::SetProxyConnectFailed()
{
}
void
NullHttpTransaction::Close(nsresult reason)
{
mStatus = reason;
mConnection = nullptr;
mIsDone = true;
if (mActivityDistributor) {
// Report that this transaction is closing.
NS_DispatchToMainThread(new CallObserveActivity(mActivityDistributor,
mConnectionInfo->GetHost(),
mConnectionInfo->Port(),
mConnectionInfo->EndToEndSSL(),
NS_HTTP_ACTIVITY_TYPE_HTTP_TRANSACTION,
NS_HTTP_ACTIVITY_SUBTYPE_TRANSACTION_CLOSE,
PR_Now(), 0, EmptyCString()));
}
}
nsHttpConnectionInfo *
NullHttpTransaction::ConnectionInfo()
{
return mConnectionInfo;
}
nsresult
NullHttpTransaction::AddTransaction(nsAHttpTransaction *trans)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
uint32_t
NullHttpTransaction::PipelineDepth()
{
return 0;
}
nsresult
NullHttpTransaction::SetPipelinePosition(int32_t position)
{
return NS_OK;
}
int32_t
NullHttpTransaction::PipelinePosition()
{
return 1;
}
} // namespace mozilla::net
} // namespace mozilla