Fix for SATIZENVUL-1655 & SATIZENVUL-1656 - error handling 31/191831/4
authorAbhishek Vijay <abhishek.v@samsung.com>
Wed, 24 Oct 2018 09:01:04 +0000 (14:31 +0530)
committerAbhishek Vijay <abhishek.v@samsung.com>
Thu, 25 Oct 2018 08:36:35 +0000 (14:06 +0530)
Change-Id: Ib1aa5f0f37ccd352296e40c01ea25083a1524dc5
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
common/cryptoutil/src/AsmCrypto.cpp
server/src/ClientListener.cpp

index f919196..4c989f5 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;
index 0e84279..110837c 100755 (executable)
@@ -96,13 +96,19 @@ ClientListner::readProc(const char *path, char *buf, int size)
        ret = read(fd, buf, size - 1);
        if (ret <= 0) {
                _ERR("fd read error(%d)\n", fd);
-               close(fd);
+
+               if (close(fd) == -1);
+                       _ERR("fd close error");
+
                return -1;
        } else {
                buf[ret] = 0;
        }
 
-       close(fd);
+       if (close(fd) == -1) {
+               _ERR("fd close error");
+               return -1;
+       }
 
        return ret;
 }