Bug 1621539 - Replace PL_Base64Encode with Base64Encode r=valentin
authorMahakBansal <mbansal@cs.iitr.ac.in>
Sun, 15 Mar 2020 19:24:39 +0000
changeset 518876 1b9ae8d988450edc8dca7fb7e19f577bb92deb48
parent 518875 f9fc9427476eb418b9032257f116ad614f0ae5b2
child 518877 da9cb42c5dc6f7d993354816e2ab43878d1afaa9
push id37218
push userrmaries@mozilla.com
push dateMon, 16 Mar 2020 09:28:04 +0000
treeherdermozilla-central@6199f7b91e8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1621539
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1621539 - Replace PL_Base64Encode with Base64Encode r=valentin Differential Revision: https://phabricator.services.mozilla.com/D66452
netwerk/protocol/websocket/WebSocketChannel.cpp
--- a/netwerk/protocol/websocket/WebSocketChannel.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannel.cpp
@@ -40,16 +40,17 @@
 #include "nsIObserverService.h"
 #include "nsCharSeparatedTokenizer.h"
 
 #include "nsNetCID.h"
 #include "nsServiceManagerUtils.h"
 #include "nsCRT.h"
 #include "nsThreadUtils.h"
 #include "nsError.h"
+#include "mozilla/Base64.h"
 #include "nsStringStream.h"
 #include "nsAlgorithm.h"
 #include "nsProxyRelease.h"
 #include "nsNetUtil.h"
 #include "nsINode.h"
 #include "mozilla/StaticMutex.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
@@ -2733,21 +2734,22 @@ nsresult WebSocketChannel::SetupRequest(
     MOZ_ASSERT(NS_SUCCEEDED(rv));
   }
 
   uint8_t* secKey;
   nsAutoCString secKeyString;
 
   rv = mRandomGenerator->GenerateRandomBytes(16, &secKey);
   NS_ENSURE_SUCCESS(rv, rv);
-  char* b64 = PL_Base64Encode((const char*)secKey, 16, nullptr);
+  rv = Base64Encode(nsDependentCSubstring((char*)secKey, 16), secKeyString);
   free(secKey);
-  if (!b64) return NS_ERROR_OUT_OF_MEMORY;
-  secKeyString.Assign(b64);
-  PR_Free(b64);  // PL_Base64Encode() uses PR_Malloc.
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+
   rv = mHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Sec-WebSocket-Key"),
                                       secKeyString, false);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
   LOG(("WebSocketChannel::SetupRequest: client key %s\n", secKeyString.get()));
 
   // prepare the value we expect to see in
   // the sec-websocket-accept response header
   rv = CalculateWebSocketHashedSecret(secKeyString, mHashedSecret);