Fix potential overflow in AEAD IV length

This commit is contained in:
Davide De Rosa 2019-02-25 23:23:43 +01:00
parent 0750d860ba
commit d1b5c94be9
1 changed files with 2 additions and 2 deletions

View File

@ -129,7 +129,7 @@ static const NSInteger CryptoAEADTagLength = 16;
int code = 1;
assert(flags->adLength >= PacketIdLength);
memcpy(self.cipherIVEnc, flags->iv, flags->ivLength);
memcpy(self.cipherIVEnc, flags->iv, MIN(flags->ivLength, self.cipherIVLength));
TUNNEL_CRYPTO_TRACK_STATUS(code) EVP_CipherInit(self.cipherCtxEnc, NULL, NULL, self.cipherIVEnc, -1);
TUNNEL_CRYPTO_TRACK_STATUS(code) EVP_CipherUpdate(self.cipherCtxEnc, NULL, &x, flags->ad, (int)flags->adLength);
@ -175,7 +175,7 @@ static const NSInteger CryptoAEADTagLength = 16;
int code = 1;
assert(flags->adLength >= PacketIdLength);
memcpy(self.cipherIVDec, flags->iv, flags->ivLength);
memcpy(self.cipherIVDec, flags->iv, MIN(flags->ivLength, self.cipherIVLength));
TUNNEL_CRYPTO_TRACK_STATUS(code) EVP_CipherInit(self.cipherCtxDec, NULL, NULL, self.cipherIVDec, -1);
TUNNEL_CRYPTO_TRACK_STATUS(code) EVP_CIPHER_CTX_ctrl(self.cipherCtxDec, EVP_CTRL_GCM_SET_TAG, CryptoAEADTagLength, (uint8_t *)bytes);