From aa9d2f4bbc00d0660fe30325daa9dd9b3323dadc Mon Sep 17 00:00:00 2001 From: huangxin Date: Mon, 5 Dec 2022 18:12:09 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E4=BF=AE=E6=AD=A3=E4=B8=80=E5=A4=84?= =?UTF-8?q?BASE64=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/libs/crypto/base64.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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; }