mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 11:17:29 +02:00
Fix to check for buffer overrrun with the additional padding in PKCS12 EncryptContent
function.
This commit is contained in:
@@ -3245,12 +3245,17 @@ int EncryptContent(byte* input, word32 inputSz, byte* out, word32* outSz,
|
|||||||
sz = SetLength(inputSz, out + inOutIdx);
|
sz = SetLength(inputSz, out + inOutIdx);
|
||||||
inOutIdx += sz; totalSz += sz;
|
inOutIdx += sz; totalSz += sz;
|
||||||
|
|
||||||
/* adjust size to pad */
|
/* get pad size and verify buffer room */
|
||||||
sz = Pkcs8Pad(out + inOutIdx, inputSz, blockSz);
|
sz = Pkcs8Pad(NULL, inputSz, blockSz);
|
||||||
if (sz + inOutIdx > *outSz)
|
if (sz + inOutIdx > *outSz)
|
||||||
return BUFFER_E;
|
return BUFFER_E;
|
||||||
|
|
||||||
|
/* copy input to output buffer and pad end */
|
||||||
XMEMCPY(out + inOutIdx, input, inputSz);
|
XMEMCPY(out + inOutIdx, input, inputSz);
|
||||||
|
sz = Pkcs8Pad(out + inOutIdx, inputSz, blockSz);
|
||||||
|
totalSz += sz;
|
||||||
|
|
||||||
|
/* encrypt */
|
||||||
if ((ret = wc_CryptKey(password, passwordSz, salt, saltSz, itt, id,
|
if ((ret = wc_CryptKey(password, passwordSz, salt, saltSz, itt, id,
|
||||||
out + inOutIdx, sz, version, cbcIv, 1)) < 0) {
|
out + inOutIdx, sz, version, cbcIv, 1)) < 0) {
|
||||||
|
|
||||||
@@ -3265,7 +3270,6 @@ int EncryptContent(byte* input, word32 inputSz, byte* out, word32* outSz,
|
|||||||
XFREE(cbcIv, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(cbcIv, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
XFREE(saltTmp, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(saltTmp, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
#endif
|
#endif
|
||||||
totalSz += sz;
|
|
||||||
|
|
||||||
return totalSz;
|
return totalSz;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user