Bug 1344081 - Switch to Base64Decode in nsHttpNegotiateAuth::GenerateCredentials. r=jduell a=gchang
authorEric Rahm <erahm@mozilla.com>
Mon, 13 Mar 2017 19:09:26 -0700
changeset 395327 89e07f8033ba961a5dd0b1d613c523493336c8ff
parent 395326 81032f42c222ddf15587686708c0940f1b58a69a
child 395328 b25235239f9ba35586466aee8b8d2f49068ee550
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell, gchang
bugs1344081
milestone54.0a2
Bug 1344081 - Switch to Base64Decode in nsHttpNegotiateAuth::GenerateCredentials. r=jduell a=gchang MozReview-Commit-ID: 4A5tEV5Fb8
extensions/auth/nsHttpNegotiateAuth.cpp
--- a/extensions/auth/nsHttpNegotiateAuth.cpp
+++ b/extensions/auth/nsHttpNegotiateAuth.cpp
@@ -27,16 +27,17 @@
 #include "nsIPrefBranch.h"
 #include "nsIProxyInfo.h"
 #include "nsIURI.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsNetCID.h"
 #include "plbase64.h"
 #include "plstr.h"
+#include "mozilla/Base64.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Tokenizer.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Unused.h"
 #include "prmem.h"
 #include "prnetdb.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Sprintf.h"
@@ -44,16 +45,18 @@
 #include "nsNetUtil.h"
 #include "nsThreadUtils.h"
 #include "nsIHttpAuthenticatorCallback.h"
 #include "mozilla/Mutex.h"
 #include "nsICancelable.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/net/HttpAuthUtils.h"
 
+using mozilla::Base64Decode;
+
 //-----------------------------------------------------------------------------
 
 static const char kNegotiate[] = "Negotiate";
 static const char kNegotiateAuthTrustedURIs[] = "network.negotiate-auth.trusted-uris";
 static const char kNegotiateAuthDelegationURIs[] = "network.negotiate-auth.delegation-uris";
 static const char kNegotiateAuthAllowProxies[] = "network.negotiate-auth.allow-proxies";
 static const char kNegotiateAuthAllowNonFqdn[] = "network.negotiate-auth.allow-non-fqdn";
 static const char kNegotiateAuthSSPI[] = "network.auth.use-sspi";
@@ -530,27 +533,24 @@ nsHttpNegotiateAuth::GenerateCredentials
         while (*challenge == ' ')
             challenge++;
         len = strlen(challenge);
 
         // strip off any padding (see bug 230351)
         while (challenge[len - 1] == '=')
             len--;
 
-        inTokenLen = (len * 3)/4;
-        inToken = malloc(inTokenLen);
-        if (!inToken)
-            return (NS_ERROR_OUT_OF_MEMORY);
-
         //
         // Decode the response that followed the "Negotiate" token
         //
-        if (PL_Base64Decode(challenge, len, (char *) inToken) == nullptr) {
-            free(inToken);
-            return(NS_ERROR_UNEXPECTED);
+        nsresult rv =
+            Base64Decode(challenge, len, (char**)&inToken, &inTokenLen);
+
+        if (NS_FAILED(rv)) {
+            return rv;
         }
     }
     else {
         //
         // Initializing, don't use an input token.
         //
         inToken = nullptr;
         inTokenLen = 0;