Check return value of malloc

fixes #27

//FREEBIE
pull/1/head
Ronny 9 years ago committed by Michael Kirk
parent 91fcd01632
commit 556dca6502

@ -112,6 +112,11 @@
size_t bufferSize = [dataToEncrypt length] + kCCBlockSizeAES128; size_t bufferSize = [dataToEncrypt length] + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize); void *buffer = malloc(bufferSize);
if (buffer == NULL) {
DDLogError(@"Failed to allocate memory.");
return nil;
}
size_t bytesEncrypted = 0; size_t bytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
kCCAlgorithmAES128, kCCAlgorithmAES128,
@ -190,6 +195,11 @@
size_t bufferSize = [dataToDecrypt length] + kCCBlockSizeAES128; size_t bufferSize = [dataToDecrypt length] + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize); void *buffer = malloc(bufferSize);
if (buffer == NULL) {
DDLogError(@"Failed to allocate memory.");
return nil;
}
size_t bytesDecrypted = 0; size_t bytesDecrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,
kCCAlgorithmAES128, kCCAlgorithmAES128,

Loading…
Cancel
Save