Merge "Fix for SATIZENVUL-1655 & SATIZENVUL-1656 - error handling" into tizen
[platform/core/account/fido-asm.git] / common / cryptoutil / src / AsmCrypto.cpp
index 485ed21..c89da83 100755 (executable)
@@ -935,6 +935,11 @@ __get_pub_key_from_cert(const char *cert_b64)
        int hashed_len = 0;
 
        der_pubkey_temp = der_pubkey = (unsigned char*)OPENSSL_malloc(der_len);
+       if (der_pubkey_temp == NULL || der_pubkey == NULL) {
+               _ERR("OPENSSL_malloc failed for der_pubkey");
+               free(cert_raw);
+               return NULL;
+       }
 
        i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x509), (unsigned char **)&der_pubkey_temp);
 
@@ -1143,7 +1148,13 @@ AsmCrypto::fidoSignWithKey(const unsigned char *msg, int msg_len,
 
        size_t sig_len_loc = 0;
        EVP_DigestSignFinal(mdctx, NULL, &sig_len_loc);
+
        unsigned char *sig = (unsigned char *)OPENSSL_malloc(sizeof(unsigned char) * (sig_len_loc));
+       if (sig == NULL) {
+               _ERR("OPENSSL_malloc failed");
+               return NULL;
+       }
+
        EVP_DigestSignFinal(mdctx, sig, &sig_len_loc);
 
        *sig_len = sig_len_loc;
@@ -1200,7 +1211,13 @@ AsmCrypto::fidoSign(const unsigned char *msg, int msg_len, const char *private_k
 
        size_t sig_len_loc = 0;
        EVP_DigestSignFinal(mdctx, NULL, &sig_len_loc);
+
        unsigned char *sig = (unsigned char *)OPENSSL_malloc(sizeof(unsigned char) * (sig_len_loc));
+       if (sig == NULL) {
+               _ERR("OPENSSL_malloc failed");
+               return NULL;
+       }
+
        EVP_DigestSignFinal(mdctx, sig, &sig_len_loc);
 
        *sig_len = sig_len_loc;