From 556dca650210da9c4336f1cb5dd772882d60b0c0 Mon Sep 17 00:00:00 2001 From: Ronny Date: Mon, 3 Oct 2016 10:58:49 +0200 Subject: [PATCH] Check return value of malloc fixes #27 //FREEBIE --- src/Util/Cryptography.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Util/Cryptography.m b/src/Util/Cryptography.m index f46a9a6f6..1d327b8ec 100755 --- a/src/Util/Cryptography.m +++ b/src/Util/Cryptography.m @@ -111,6 +111,11 @@ */ size_t bufferSize = [dataToEncrypt length] + kCCBlockSizeAES128; void *buffer = malloc(bufferSize); + + if (buffer == NULL) { + DDLogError(@"Failed to allocate memory."); + return nil; + } size_t bytesEncrypted = 0; CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, @@ -189,6 +194,11 @@ // decrypt size_t bufferSize = [dataToDecrypt length] + kCCBlockSizeAES128; void *buffer = malloc(bufferSize); + + if (buffer == NULL) { + DDLogError(@"Failed to allocate memory."); + return nil; + } size_t bytesDecrypted = 0; CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,