perf(error):
memory out of size in UtilityNative2PKCS()
@@ -1286,14 +1286,15 @@ BCHAR* UtilityNative2PKCS(KeypairNative keypair){
len = offset_bat;
offset = 0;
add_TL_withOffset((BoAT_ASN1_CONSTRUCTED | BoAT_ASN1_SEQUENCE) ,dataHex,&offset,len); //all
- outStr = BoatMalloc(offset + strlen(PRIKEY_PKCS_BEGIN) + strlen(PRIKEY_PKCS_END) + 6) ;
+ offset_bat = (((offset -1)/3)+1)*4;
+ outStr = BoatMalloc(offset_bat + strlen(PRIKEY_PKCS_BEGIN) + strlen(PRIKEY_PKCS_END) + 6) ;
if(NULL == outStr){
if(dataHex != NULL){
BoatFree(dataHex);
}
return NULL;
}
- memset(outStr,0,offset + strlen(PRIKEY_PKCS_BEGIN) + strlen(PRIKEY_PKCS_END) + 6);
+ memset(outStr,0,offset_bat + strlen(PRIKEY_PKCS_BEGIN) + strlen(PRIKEY_PKCS_END) + 6);
len = BoAT_base64_encode(dataHex,offset,outStr+strlen(PRIKEY_PKCS_BEGIN)+2);
memcpy(outStr,PRIKEY_PKCS_BEGIN,strlen(PRIKEY_PKCS_BEGIN));
offset = strlen(PRIKEY_PKCS_BEGIN);
@@ -1303,6 +1304,7 @@ BCHAR* UtilityNative2PKCS(KeypairNative keypair){
outStr[offset++] = 0x0D;
outStr[offset++] = 0x0A;
memcpy(outStr + offset,PRIKEY_PKCS_END,strlen(PRIKEY_PKCS_BEGIN));
+ offset += strlen(PRIKEY_PKCS_BEGIN);
outStr[offset++] = 0x0D;
outStr[offset++] = 0x0A;
BoatFree(dataHex);
