Merge pull request #2550 from cconlon/mmcau

fix mmCAU classic XFREE on aligned ptr
This commit is contained in:
David Garske
2019-11-01 15:59:57 -07:00
committed by GitHub

View File

@@ -1920,6 +1920,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
byte* rk = (byte*)aes->key; byte* rk = (byte*)aes->key;
byte* tmpKey = (byte*)userKey; byte* tmpKey = (byte*)userKey;
int tmpKeyDynamic = 0; int tmpKeyDynamic = 0;
word32 alignOffset = 0;
(void)dir; (void)dir;
@@ -1943,8 +1944,9 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
if (tmp == NULL) { if (tmp == NULL) {
return MEMORY_E; return MEMORY_E;
} }
tmpKey = tmp + (WOLFSSL_MMCAU_ALIGNMENT - alignOffset = WOLFSSL_MMCAU_ALIGNMENT -
((wolfssl_word)tmp % WOLFSSL_MMCAU_ALIGNMENT)); ((wolfssl_word)tmp % WOLFSSL_MMCAU_ALIGNMENT);
tmpKey = tmp + alignOffset;
XMEMCPY(tmpKey, userKey, keylen); XMEMCPY(tmpKey, userKey, keylen);
tmpKeyDynamic = 1; tmpKeyDynamic = 1;
#else #else
@@ -1967,7 +1969,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
} }
if (tmpKeyDynamic == 1) { if (tmpKeyDynamic == 1) {
XFREE(tmpKey, aes->heap, DYNAMIC_TYPE_TMP_BUFFER); XFREE(tmpKey - alignOffset, aes->heap, DYNAMIC_TYPE_TMP_BUFFER);
} }
return ret; return ret;