OCT 1. 修正一处BASE64解析失败BUG
This commit is contained in:
parent
ca3002ecfb
commit
aa9d2f4bbc
|
@ -4,6 +4,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <openssl/aes.h>
|
#include <openssl/aes.h>
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
|
#include <zlog.h>
|
||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
@ -121,12 +122,17 @@ unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize) {
|
||||||
size = (int)strlen(pBase64);
|
size = (int)strlen(pBase64);
|
||||||
pDecode = (unsigned char *)malloc(size);
|
pDecode = (unsigned char *)malloc(size);
|
||||||
memset(pDecode, 0, size);
|
memset(pDecode, 0, size);
|
||||||
|
|
||||||
#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
|
#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||||
EVP_DecodeInit(&ctx);
|
EVP_DecodeInit(&ctx);
|
||||||
EVP_DecodeUpdate(&ctx, pDecode, &enSize, (const unsigned char *)pBase64, strlen(pBase64));
|
EVP_DecodeUpdate(&ctx, pDecode, &enSize, (const unsigned char *)pBase64, strlen(pBase64));
|
||||||
#else
|
#else
|
||||||
EVP_DecodeInit(pCtx);
|
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
|
#endif
|
||||||
if (pOutSize) {
|
if (pOutSize) {
|
||||||
*pOutSize = enSize;
|
*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
|
#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||||
EVP_DecodeFinal(&ctx, pDecode + enSize, &size);
|
EVP_DecodeFinal(&ctx, pDecode + enSize, &size);
|
||||||
#else
|
#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);
|
EVP_ENCODE_CTX_free(pCtx);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return pDecode;
|
return pDecode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue