Merge pull request #7209 from philljj/zd17416

Coverity issues: fix MD5 and SHA buffer overrun.
This commit is contained in:
Sean Parkinson
2024-02-06 08:58:27 +10:00
committed by GitHub
4 changed files with 17 additions and 5 deletions

View File

@ -461,7 +461,9 @@ int wc_Md5Final(wc_Md5* md5, byte* hash)
/* pad with zeros */ /* pad with zeros */
if (md5->buffLen > WC_MD5_PAD_SIZE) { if (md5->buffLen > WC_MD5_PAD_SIZE) {
XMEMSET(&local[md5->buffLen], 0, WC_MD5_BLOCK_SIZE - md5->buffLen); if (md5->buffLen < WC_MD5_BLOCK_SIZE) {
XMEMSET(&local[md5->buffLen], 0, WC_MD5_BLOCK_SIZE - md5->buffLen);
}
md5->buffLen += WC_MD5_BLOCK_SIZE - md5->buffLen; md5->buffLen += WC_MD5_BLOCK_SIZE - md5->buffLen;
#if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU_SHA) #if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU_SHA)

View File

@ -841,7 +841,10 @@ int wc_ShaFinal(wc_Sha* sha, byte* hash)
/* pad with zeros */ /* pad with zeros */
if (sha->buffLen > WC_SHA_PAD_SIZE) { if (sha->buffLen > WC_SHA_PAD_SIZE) {
XMEMSET(&local[sha->buffLen], 0, WC_SHA_BLOCK_SIZE - sha->buffLen); if (sha->buffLen < WC_SHA_BLOCK_SIZE) {
XMEMSET(&local[sha->buffLen], 0, WC_SHA_BLOCK_SIZE - sha->buffLen);
}
sha->buffLen += WC_SHA_BLOCK_SIZE - sha->buffLen; sha->buffLen += WC_SHA_BLOCK_SIZE - sha->buffLen;
#if defined(WOLFSSL_USE_ESP32_CRYPT_HASH_HW) #if defined(WOLFSSL_USE_ESP32_CRYPT_HASH_HW)

View File

@ -1321,8 +1321,11 @@ static int InitSha256(wc_Sha256* sha256)
/* pad with zeros */ /* pad with zeros */
if (sha256->buffLen > WC_SHA256_PAD_SIZE) { if (sha256->buffLen > WC_SHA256_PAD_SIZE) {
XMEMSET(&local[sha256->buffLen], 0, if (sha256->buffLen < WC_SHA256_BLOCK_SIZE) {
WC_SHA256_BLOCK_SIZE - sha256->buffLen); XMEMSET(&local[sha256->buffLen], 0,
WC_SHA256_BLOCK_SIZE - sha256->buffLen);
}
sha256->buffLen += WC_SHA256_BLOCK_SIZE - sha256->buffLen; sha256->buffLen += WC_SHA256_BLOCK_SIZE - sha256->buffLen;
#if defined(WOLFSSL_USE_ESP32_CRYPT_HASH_HW) && \ #if defined(WOLFSSL_USE_ESP32_CRYPT_HASH_HW) && \

View File

@ -942,7 +942,11 @@ static WC_INLINE int Sha512Final(wc_Sha512* sha512)
/* pad with zeros */ /* pad with zeros */
if (sha512->buffLen > WC_SHA512_PAD_SIZE) { if (sha512->buffLen > WC_SHA512_PAD_SIZE) {
XMEMSET(&local[sha512->buffLen], 0, WC_SHA512_BLOCK_SIZE - sha512->buffLen); if (sha512->buffLen < WC_SHA512_BLOCK_SIZE ) {
XMEMSET(&local[sha512->buffLen], 0,
WC_SHA512_BLOCK_SIZE - sha512->buffLen);
}
sha512->buffLen += WC_SHA512_BLOCK_SIZE - sha512->buffLen; sha512->buffLen += WC_SHA512_BLOCK_SIZE - sha512->buffLen;
#if defined(LITTLE_ENDIAN_ORDER) #if defined(LITTLE_ENDIAN_ORDER)
#if defined(USE_INTEL_SPEEDUP) && \ #if defined(USE_INTEL_SPEEDUP) && \