Protect from failed allocations

Project: 
http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-core/commit/c7805ec4
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-core/tree/c7805ec4
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-core/diff/c7805ec4

Branch: refs/heads/master
Commit: c7805ec4576b5d70e46a4e450abd12a06780c440
Parents: acd0530
Author: Simeon Aladjem <[email protected]>
Authored: Fri Apr 15 17:01:20 2016 +0300
Committer: Simeon Aladjem <[email protected]>
Committed: Fri Apr 15 17:01:20 2016 +0300

----------------------------------------------------------------------
 src/mpin_crypto_non_tee.cpp | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-core/blob/c7805ec4/src/mpin_crypto_non_tee.cpp
----------------------------------------------------------------------
diff --git a/src/mpin_crypto_non_tee.cpp b/src/mpin_crypto_non_tee.cpp
index 77cdbc0..ebc991c 100644
--- a/src/mpin_crypto_non_tee.cpp
+++ b/src/mpin_crypto_non_tee.cpp
@@ -42,18 +42,27 @@ public:
 
 Octet::Octet(size_t maxSize)
 {
-    this->max = maxSize;
+    this->max = 0;
     this->len = 0;
     this->val = (char *) calloc(maxSize, 1);
+       if(this->val != NULL)
+       {
+               this->max = maxSize;            
+       }               
 }
 
 Octet::Octet(const String& str)
 {
+    this->max = 0;
+    this->len = 0;
     size_t maxSize = str.size();
-    this->max = maxSize;
-    this->len = maxSize;
     this->val = (char *) malloc(maxSize);
-    memcpy(this->val, str.c_str(), maxSize);
+       if(this->val != NULL)
+       {
+               this->max = maxSize;
+               this->len = maxSize;
+               memcpy(this->val, str.c_str(), maxSize);                
+       }
 }
 
 Octet::~Octet()

Reply via email to