зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1398646: Forbid sync DNS resolution on the main thread. r=valentin
MozReview-Commit-ID: A6mUDNSri2m --HG-- extra : rebase_source : 43c58d61614e186b89523a301fd1d2d8bd99a503 extra : source : 963bf9d8573273894016e7082cb5f3fb85d80661
This commit is contained in:
Родитель
6ddfbd4f2a
Коммит
63d03a767b
|
@ -24,6 +24,10 @@ else:
|
|||
'nsAuthSambaNTLM.cpp',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/netwerk/dns', # For nsDNSService2.h
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
with Files('**'):
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
//
|
||||
|
||||
#include "nsAuthSSPI.h"
|
||||
#include "nsDNSService2.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIDNSService.h"
|
||||
#include "nsIDNSRecord.h"
|
||||
|
@ -92,8 +93,8 @@ InitSSPI()
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static nsresult
|
||||
MakeSN(const char *principal, nsCString &result)
|
||||
nsresult
|
||||
nsAuthSSPI::MakeSN(const char *principal, nsCString &result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -106,10 +107,12 @@ MakeSN(const char *principal, nsCString &result)
|
|||
if (index == kNotFound)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIDNSService> dnsService = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
auto dns = static_cast<nsDNSService*>(dnsService.get());
|
||||
|
||||
// This could be expensive if our DNS cache cannot satisfy the request.
|
||||
// However, we should have at least hit the OS resolver once prior to
|
||||
// reaching this code, so provided the OS resolver has this information
|
||||
|
@ -120,10 +123,10 @@ MakeSN(const char *principal, nsCString &result)
|
|||
// its cache. This is not an issue in versions of Windows up to WinXP.
|
||||
nsCOMPtr<nsIDNSRecord> record;
|
||||
mozilla::OriginAttributes attrs;
|
||||
rv = dns->ResolveNative(Substring(buf, index + 1),
|
||||
nsIDNSService::RESOLVE_CANONICAL_NAME,
|
||||
attrs,
|
||||
getter_AddRefs(record));
|
||||
rv = dns->DeprecatedSyncResolve(Substring(buf, index + 1),
|
||||
nsIDNSService::RESOLVE_CANONICAL_NAME,
|
||||
attrs,
|
||||
getter_AddRefs(record));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ private:
|
|||
typedef TimeStamp MS_TimeStamp;
|
||||
|
||||
private:
|
||||
nsresult MakeSN(const char *principal, nsCString &result);
|
||||
|
||||
CredHandle mCred;
|
||||
CtxtHandle mCtxt;
|
||||
nsCString mServiceName;
|
||||
|
|
|
@ -991,6 +991,29 @@ nsDNSService::ResolveNative(const nsACString &aHostname,
|
|||
uint32_t flags,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsIDNSRecord **result)
|
||||
{
|
||||
// Synchronous resolution is not available on the main thread.
|
||||
if (NS_IsMainThread()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
return ResolveInternal(aHostname, flags, aOriginAttributes, result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDNSService::DeprecatedSyncResolve(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsIDNSRecord **result)
|
||||
{
|
||||
return ResolveInternal(aHostname, flags, aOriginAttributes, result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDNSService::ResolveInternal(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
const OriginAttributes &aOriginAttributes,
|
||||
nsIDNSRecord **result)
|
||||
{
|
||||
// grab reference to global host resolver and IDN service. beware
|
||||
// simultaneous shutdown!!
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
class nsAuthSSPI;
|
||||
|
||||
class nsDNSService final : public nsPIDNSService
|
||||
, public nsIObserver
|
||||
, public nsIMemoryReporter
|
||||
|
@ -38,6 +40,14 @@ public:
|
|||
|
||||
bool GetOffline() const;
|
||||
|
||||
protected:
|
||||
friend class nsAuthSSPI;
|
||||
|
||||
nsresult DeprecatedSyncResolve(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
const mozilla::OriginAttributes &aOriginAttributes,
|
||||
nsIDNSRecord **result);
|
||||
|
||||
private:
|
||||
~nsDNSService();
|
||||
|
||||
|
@ -50,6 +60,11 @@ private:
|
|||
nsIIDNService *aIDN,
|
||||
nsACString &aACE);
|
||||
|
||||
nsresult ResolveInternal(const nsACString &aHostname,
|
||||
uint32_t flags,
|
||||
const mozilla::OriginAttributes &aOriginAttributes,
|
||||
nsIDNSRecord **result);
|
||||
|
||||
RefPtr<nsHostResolver> mResolver;
|
||||
nsCOMPtr<nsIIDNService> mIDN;
|
||||
|
||||
|
|
|
@ -99,9 +99,10 @@ interface nsIDNSService : nsISupports
|
|||
in OriginAttributes aOriginAttributes);
|
||||
|
||||
/**
|
||||
* called to synchronously resolve a hostname. warning this method may
|
||||
* block the calling thread for a long period of time. it is extremely
|
||||
* unwise to call this function on the UI thread of an application.
|
||||
* called to synchronously resolve a hostname.
|
||||
*
|
||||
* Since this method may block the calling thread for a long period of
|
||||
* time, it may not be accessed from the main thread.
|
||||
*
|
||||
* @param aHostName
|
||||
* the hostname or IP-address-literal to resolve.
|
||||
|
@ -114,6 +115,7 @@ interface nsIDNSService : nsISupports
|
|||
*
|
||||
* @return DNS record corresponding to the given hostname.
|
||||
* @throws NS_ERROR_UNKNOWN_HOST if host could not be resolved.
|
||||
* @throws NS_ERROR_NOT_AVAILABLE if accessed from the main thread.
|
||||
*/
|
||||
[implicit_jscontext, optional_argc]
|
||||
nsIDNSRecord resolve(in AUTF8String aHostName,
|
||||
|
|
Загрузка…
Ссылка в новой задаче