[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser/tor-browser-52.8.0esr-7.5-1] Bug 1444532 - Fix a leak in SHA256 in nsHttpConnectionInfo.cpp. r=mayhemer, a=jcristau



commit 4edbd21ab9244671cb77cf9a4de5e1126079146e
Author: David Keeler <dkeeler@xxxxxxxxxxx>
Date:   Fri Mar 9 14:16:57 2018 -0800

    Bug 1444532 - Fix a leak in SHA256 in nsHttpConnectionInfo.cpp. r=mayhemer, a=jcristau
    
    The original code (from bug 1200802) declared an XPCOM object as a static bare
    pointer, which for future reference is probably never the right thing to do. It
    might have worked if it was cleared before shutdown but it never was.
    
    MozReview-Commit-ID: EMe7wgzm6zv
    
    --HG--
    extra : rebase_source : 16c36a76e39b762e87c7d3c74e64204d7ca9929d
    extra : source : ad1e07a06363096efbfbf115cbc274c4ee9dcd40
---
 netwerk/protocol/http/nsHttpConnectionInfo.cpp | 28 +++++++++++---------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/netwerk/protocol/http/nsHttpConnectionInfo.cpp b/netwerk/protocol/http/nsHttpConnectionInfo.cpp
index e965fd1cc2e9..4b9c84a7ed62 100644
--- a/netwerk/protocol/http/nsHttpConnectionInfo.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionInfo.cpp
@@ -14,33 +14,29 @@
 #define LOG_ENABLED() LOG5_ENABLED()
 
 #include "nsHttpConnectionInfo.h"
+
 #include "mozilla/net/DNS.h"
-#include "prnetdb.h"
-#include "nsICryptoHash.h"
 #include "nsComponentManagerUtils.h"
+#include "nsICryptoHash.h"
 #include "nsIProtocolProxyService.h"
+#include "nsNetCID.h"
+#include "prnetdb.h"
 
 static nsresult
 SHA256(const char* aPlainText, nsAutoCString& aResult)
 {
-  static nsICryptoHash* hasher = nullptr;
-  nsresult rv;
-  if (!hasher) {
-    rv = CallCreateInstance("@mozilla.org/security/hash;1", &hasher);
+    nsresult rv;
+    nsCOMPtr<nsICryptoHash> hasher =
+      do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv);
     if (NS_FAILED(rv)) {
       LOG(("nsHttpDigestAuth: no crypto hash!\n"));
       return rv;
     }
-  }
-
-  rv = hasher->Init(nsICryptoHash::SHA256);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = hasher->Update((unsigned char*) aPlainText, strlen(aPlainText));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = hasher->Finish(false, aResult);
-  return rv;
+    rv = hasher->Init(nsICryptoHash::SHA256);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = hasher->Update((unsigned char*) aPlainText, strlen(aPlainText));
+    NS_ENSURE_SUCCESS(rv, rv);
+    return hasher->Finish(false, aResult);
 }
 
 namespace mozilla {

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits