]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - lib/sspwin32.cc
SourceFormat Enforcement
[thirdparty/squid.git] / lib / sspwin32.cc
index dd437beb08639e9c04c80649da1bc778a727f288..425273199604d93809f9a949aa91d20df4714b93 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -462,7 +462,6 @@ const char * WINAPI SSP_MakeChallenge(PVOID PNegotiateBuf, int NegotiateLen)
     DWORD       cbOut      = 0;
     DWORD       cbIn       = 0;
     ntlm_challenge * challenge;
-    const char * encoded = NULL;
 
     if (NTLM_asServer.fHaveCtxtHandle)
         _DeleteSecurityContext(&NTLM_asServer.hctxt);
@@ -490,9 +489,17 @@ const char * WINAPI SSP_MakeChallenge(PVOID PNegotiateBuf, int NegotiateLen)
         challenge = (ntlm_challenge *) fResult;
         Use_Unicode = NTLM_NEGOTIATE_UNICODE & challenge->flags;
         NTLM_LocalCall = NTLM_NEGOTIATE_THIS_IS_LOCAL_CALL & challenge->flags;
-        encoded = base64_encode_bin((char *) fResult, cbOut);
+        struct base64_encode_ctx ctx;
+        base64_encode_init(&ctx);
+        static uint8_t encoded[8192];
+        size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast<const uint8_t*>(fResult));
+        assert(dstLen < sizeof(encoded));
+        dstLen += base64_encode_final(&ctx, encoded+dstLen);
+        assert(dstLen < sizeof(encoded));
+        encoded[dstLen] = '\0';
+        return reinterpret_cast<char *>(encoded);
     }
-    return encoded;
+    return NULL;
 }
 
 BOOL WINAPI SSP_ValidateNTLMCredentials(PVOID PAutenticateBuf, int AutenticateLen, char * credentials)
@@ -524,7 +531,6 @@ const char * WINAPI SSP_MakeNegotiateBlob(PVOID PNegotiateBuf, int NegotiateLen,
 {
     DWORD       cbOut      = 0;
     DWORD       cbIn       = 0;
-    const char * encoded = NULL;
 
     if (NTLM_asServer.fHaveCtxtHandle)
         _DeleteSecurityContext(&NTLM_asServer.hctxt);
@@ -548,16 +554,24 @@ const char * WINAPI SSP_MakeNegotiateBlob(PVOID PNegotiateBuf, int NegotiateLen,
         }
         *Status = SSP_OK;
     } while (0);
-    if (pServerBuf != NULL && cbOut > 0)
-        encoded = base64_encode_bin((char *) pServerBuf, cbOut);
-    return encoded;
+    if (pServerBuf != NULL && cbOut > 0) {
+        struct base64_encode_ctx ctx;
+        base64_encode_init(&ctx);
+        static uint8_t encoded[8192];
+        size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast<const uint8_t*>(pServerBuf));
+        assert(dstLen < sizeof(encoded));
+        dstLen += base64_encode_final(&ctx, encoded+dstLen);
+        assert(dstLen < sizeof(encoded));
+        encoded[dstLen] = '\0';
+        return reinterpret_cast<char *>(encoded);
+    }
+    return NULL;
 }
 
 const char * WINAPI SSP_ValidateNegotiateCredentials(PVOID PAutenticateBuf, int AutenticateLen, PBOOL fDone, int * Status, char * credentials)
 {
     DWORD       cbOut      = 0;
     DWORD       cbIn       = 0;
-    const char * encoded = NULL;
 
     memcpy(pClientBuf, PAutenticateBuf, AutenticateLen);
     ZeroMemory(pServerBuf, cbMaxToken);
@@ -575,8 +589,17 @@ const char * WINAPI SSP_ValidateNegotiateCredentials(PVOID PAutenticateBuf, int
         }
         *Status = SSP_OK;
     } while (0);
-    if (pServerBuf != NULL && cbOut > 0)
-        encoded = base64_encode_bin((char *) pServerBuf, cbOut);
-    return encoded;
+    if (pServerBuf != NULL && cbOut > 0) {
+        struct base64_encode_ctx ctx;
+        base64_encode_init(&ctx);
+        static uint8_t encoded[8192];
+        size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast<const uint8_t*>(pServerBuf));
+        assert(dstLen < sizeof(encoded));
+        dstLen += base64_encode_final(&ctx, encoded+dstLen);
+        assert(dstLen < sizeof(encoded));
+        encoded[dstLen] = '\0';
+        return reinterpret_cast<char *>(encoded);
+    }
+    return NULL;
 }