Skip to content

Commit 87205f4

Browse files
sergio-nsknmoinvaz
authored andcommitted
Fix undefined behavior: strict aliasing rule violations
They leaded to overriding caller's local variables.
1 parent e7f2b0f commit 87205f4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

mz_crypt_apple.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ int32_t mz_crypt_aes_encrypt(void *handle, const void *aad, int32_t aad_size, ui
244244

245245
int32_t mz_crypt_aes_encrypt_final(void *handle, uint8_t *buf, int32_t size, uint8_t *tag, int32_t tag_size) {
246246
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
247+
size_t tag_outsize = tag_size;
247248

248249
if (!aes || !tag || !tag_size || !aes->crypt || aes->mode != MZ_AES_MODE_GCM)
249250
return MZ_PARAM_ERROR;
@@ -252,7 +253,7 @@ int32_t mz_crypt_aes_encrypt_final(void *handle, uint8_t *buf, int32_t size, uin
252253
if (aes->error != kCCSuccess)
253254
return MZ_CRYPT_ERROR;
254255

255-
aes->error = CCCryptorGCMFinal(aes->crypt, tag, (size_t *)&tag_size);
256+
aes->error = CCCryptorGCMFinal(aes->crypt, tag, &tag_outsize);
256257

257258
if (aes->error != kCCSuccess)
258259
return MZ_CRYPT_ERROR;

mz_crypt_openssl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,10 @@ int32_t mz_crypt_hmac_end(void *handle, uint8_t *digest, int32_t digest_size) {
634634
result = HMAC_Final(hmac->ctx, digest, (uint32_t *)&digest_size);
635635
}
636636
#else
637-
result = EVP_MAC_final(hmac->ctx, digest, (size_t *)&digest_size, digest_size);
637+
{
638+
size_t digest_outsize = digest_size;
639+
result = EVP_MAC_final(hmac->ctx, digest, &digest_outsize, digest_size);
640+
}
638641
#endif
639642

640643
if (!result) {

0 commit comments

Comments
 (0)