From 69b5c49ffb81b7ce00d602f6db6fcc6ff4e09f06 Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Thu, 15 Sep 2005 00:25:21 +0000 Subject: [PATCH] fixes bug 308405 "'@mozilla.org/security/hash;1' incorrectly invoked as a service in nsHttpDigestAuth.cpp" r=dougt git-svn-id: svn://10.0.0.236/trunk@180261 18797224-902f-48f8-a5cc-f745e15eee43 --- .../protocol/http/src/nsHttpDigestAuth.cpp | 32 ++++++++----------- .../protocol/http/src/nsHttpDigestAuth.h | 1 - 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.cpp b/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.cpp index 7dff84c3482..5a4947c59a5 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.cpp @@ -62,18 +62,7 @@ //----------------------------------------------------------------------------- nsHttpDigestAuth::nsHttpDigestAuth() -{ - mVerifier = do_GetService("@mozilla.org/security/hash;1"); - mGotVerifier = (mVerifier != nsnull); - -#if defined(PR_LOGGING) - if (mGotVerifier) { - LOG(("nsHttpDigestAuth: Got signature_verifier\n")); - } else { - LOG(("nsHttpDigestAuth: No signature_verifier available\n")); - } -#endif -} +{} nsHttpDigestAuth::~nsHttpDigestAuth() {} @@ -91,11 +80,17 @@ NS_IMPL_ISUPPORTS1(nsHttpDigestAuth, nsIHttpAuthenticator) nsresult nsHttpDigestAuth::MD5Hash(const char *buf, PRUint32 len) { - if (!mGotVerifier) - return NS_ERROR_NOT_INITIALIZED; - nsresult rv; + // Cache a reference to the nsICryptoHash instance since we'll be calling + // this function frequently. + if (!mVerifier) { + mVerifier = do_CreateInstance("@mozilla.org/security/hash;1", &rv); + if (NS_FAILED(rv)) { + LOG(("nsHttpDigestAuth: no crypto hash!\n")); + return rv; + } + } rv = mVerifier->Init(nsICryptoHash::MD5); if (NS_FAILED(rv)) return rv; @@ -106,9 +101,10 @@ nsHttpDigestAuth::MD5Hash(const char *buf, PRUint32 len) nsCAutoString hashString; rv = mVerifier->Finish(PR_FALSE, hashString); if (NS_FAILED(rv)) return rv; - - if (NS_SUCCEEDED(rv)) - memcpy(mHashBuf, hashString.get(), hashString.Length()); + + NS_ENSURE_STATE(hashString.Length() == sizeof(mHashBuf)); + memcpy(mHashBuf, hashString.get(), hashString.Length()); + return rv; } diff --git a/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.h b/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.h index b07282ec5de..cb1e02296ee 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.h @@ -112,7 +112,6 @@ class nsHttpDigestAuth : public nsIHttpAuthenticator protected: nsCOMPtr mVerifier; char mHashBuf[DIGEST_LENGTH]; - PRBool mGotVerifier; }; #endif // nsHttpDigestAuth_h__