remove random() accepted/tizen/unified/20210916.005930 submit/tizen/20210915.101351
authorYoungjae Shin <yj99.shin@samsung.com>
Wed, 15 Sep 2021 08:47:02 +0000 (17:47 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 15 Sep 2021 10:12:57 +0000 (19:12 +0900)
Change-Id: Ia28ff330a0b31eabe06399f7b233cd0e910816cd

subprojects/libbeyond-peer_nn/src/peer_grpc_client.cc

index 75665988a276a3b06337d8a03cb4a8492efc070a..3c15d32175a6cd6b908631352bf4006d46925f3e 100644 (file)
@@ -139,24 +139,20 @@ uint64_t Peer::GrpcClient::GetRandom()
 {
     FILE *fp;
     uint64_t seed;
+    size_t rc = 0;
 
     fp = fopen("/dev/urandom", "rb");
-    do {
-        size_t rc = 0;
-
-        if (fp != nullptr) {
-            rc = fread(&seed, 1, sizeof(seed), fp);
-            fclose(fp);
-        }
-
-        if (rc < sizeof(seed))
-            break;
+    if (fp) {
+        rc = fread(&seed, 1, sizeof(seed), fp);
+        fclose(fp);
+    }
 
-        return seed;
-    } while (false);
+    if (rc < sizeof(seed)) {
+        ErrPrint("get random Fail");
+        return 0;
+    }
 
-    srandom(static_cast<unsigned int>(time(nullptr)));
-    return random();
+    return seed;
 }
 
 int Peer::GrpcClient::ExchangeKey(void)
@@ -167,6 +163,8 @@ int Peer::GrpcClient::ExchangeKey(void)
     beyond::AuthenticatorInterface *auth = nullptr;
 
     unsigned long nonce = GetRandom();
+    if (nonce == 0)
+        return -EIO;
 
     if (peer->caAuthenticator != nullptr) {
         DbgPrint("CA Authenticator is selected");