Bug 1344081 - Switch to Base64Decode in nsHttpNegotiateAuth::GenerateCredentials. r=jduell a=gchang
authorEric Rahm <erahm@mozilla.com>
Wed, 22 Mar 2017 11:24:53 -0700
changeset 379213 0a56c49e7e25c97f6c6b6881cd86ea7c5dfa4182
parent 379212 8710cce7e0b851707e209b11c3c9c9108426d6b9
child 379214 9a13e249c5e5b5b68c211ffc0f1c8972feff69f3
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell, gchang
bugs1344081
milestone53.0
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,29 +27,32 @@
 #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 "prprf.h"
 #include "mozilla/Logging.h"
 #include "prmem.h"
 #include "prnetdb.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Sprintf.h"
 #include "nsIChannel.h"
 #include "nsNetUtil.h"
 #include "nsThreadUtils.h"
 #include "nsIHttpAuthenticatorCallback.h"
 #include "mozilla/Mutex.h"
 #include "nsICancelable.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";
@@ -526,27 +529,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;