diff --git a/srcs/libs/crypto/base64.c b/srcs/libs/crypto/base64.c index c5c64ac..8187991 100644 --- a/srcs/libs/crypto/base64.c +++ b/srcs/libs/crypto/base64.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "crypto.h" @@ -121,12 +122,17 @@ unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize) { size = (int)strlen(pBase64); pDecode = (unsigned char *)malloc(size); memset(pDecode, 0, size); + #if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L EVP_DecodeInit(&ctx); EVP_DecodeUpdate(&ctx, pDecode, &enSize, (const unsigned char *)pBase64, strlen(pBase64)); #else EVP_DecodeInit(pCtx); - EVP_DecodeUpdate(pCtx, pDecode, &enSize, (const unsigned char *)pBase64, (int)strlen(pBase64)); + if (EVP_DecodeUpdate(pCtx, pDecode, &enSize, (const unsigned char *)pBase64, size) == -1) { + dzlog_error("Decode [%s] error\n", pBase64); + free(pDecode); + return NULL; + } #endif if (pOutSize) { *pOutSize = enSize; @@ -135,8 +141,14 @@ unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize) { #if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L EVP_DecodeFinal(&ctx, pDecode + enSize, &size); #else - EVP_DecodeFinal(pCtx, pDecode + enSize, &size); + if (EVP_DecodeFinal(pCtx, pDecode, &enSize) == -1) { + dzlog_error("Finish decode [%s] error\n", pBase64); + free(pDecode); + return NULL; + } + EVP_ENCODE_CTX_free(pCtx); #endif + return pDecode; }