Fix SVACE issues 81/314481/1 accepted/tizen_9.0_unified accepted/tizen_unified_dev accepted/tizen_unified_toolchain accepted/tizen_unified_x_asan tizen_9.0 accepted/tizen/9.0/unified/20241030.234627 accepted/tizen/unified/20240829.153523 accepted/tizen/unified/dev/20240901.214710 accepted/tizen/unified/toolchain/20241004.101924 accepted/tizen/unified/x/20240830.014054 accepted/tizen/unified/x/asan/20241014.000305 tizen_9.0_m2_release
authorhyunsube.lee <hyunsube.lee@samsung.com>
Fri, 12 Jul 2024 06:43:20 +0000 (15:43 +0900)
committerhyunsube.lee <hyunsube.lee@samsung.com>
Fri, 12 Jul 2024 06:43:34 +0000 (15:43 +0900)
Change-Id: I7f97ba889f9a91fb522d6943fdc0b99d1290ff87

src/NanClientManager.cpp
src/NanDataPathManager.cpp
src/NanHal.cpp
src/NanPeerManager.cpp
src/NanServiceProvider.cpp

index 3a02b3d0b5c830c4a944cc397af9bb02cde80aa9..79b39ba2030c105d68721a98f86765b0e8a645ba 100644 (file)
@@ -30,11 +30,14 @@ NanClientManager::~NanClientManager()
 NanClient *NanClientManager::createClient(const char *path)
 {
        int clientId = getNextClientId();
-       NanClient *client =  new NanClient(clientId, path);
-       if (client != nullptr)
+       try {
+               NanClient *client =  new NanClient(clientId, path);
                add(clientId, client);
-
-       return client;
+               return client;
+       } catch (std::bad_alloc& e) {
+               NAN_LOGE("Out of memory");
+               return nullptr;
+       }
 }
 
 int NanClientManager::getNextClientId()
index c7f6393b9839ba92406b2fa7fafbbba3733256fb..6d508dae08b95ccff7b0dbca8332cefe579fa364 100644 (file)
@@ -94,13 +94,15 @@ NanDataPathInformation *NanDataPathManager::createDataPathInformation(uint16_t p
                NAN_LOGE("NanPeer is nullptr");
                return nullptr;
        }
-
-       NanDataPathInformation *info = new NanDataPathInformation(pubSubId, peer, config);
-       if (info != nullptr) {
+       try {
+               NanDataPathInformation *info = new NanDataPathInformation(pubSubId, peer, config);
                addDataPathInfo(pubSubId, peer->getPeerId(), info);
                assignDataPathInterface(info);
+               return info;
+       } catch (std::bad_alloc& e) {
+               NAN_LOGE("Out of memory");
+               return nullptr;
        }
-       return info;
 }
 
 void NanDataPathManager::addDataPathInfo(uint16_t pubSubId, uint32_t peerId,
index 84ccdb52eb8547b61723015bef7bf0390c319c79..6e4a461bccf3fcb05765911ebad7c20cf26c5e6f 100644 (file)
@@ -1031,11 +1031,7 @@ NanDataPathInitiatorRequest* NanHal::convertDataPathConfigToLegacyRequest(std::s
        }
 
        auto len = strlen(config->serviceName);
-       if (len > NAN_MAX_SERVICE_NAME_LEN) {
-               NAN_LOGE("Invalid parameter: ndpInitiatorReq->service_name_len[%zd]", len);
-               free(ndpInitiatorReq);
-               return nullptr;
-       }
+
        ndpInitiatorReq->service_name_len = len;
        memcpy(&ndpInitiatorReq->service_name,
                        config->serviceName, ndpInitiatorReq->service_name_len);
@@ -1093,11 +1089,7 @@ NanDataPathIndicationResponse* NanHal::convertDataPathConfigToLegacyResponse(std
        }
 
        auto len = strlen(config->serviceName);
-       if (len > NAN_MAX_SERVICE_NAME_LEN) {
-               NAN_LOGE("Invalid parameter: ndpIndicationResp->service_name_len[%zd]", len);
-               free(ndpIndicationResp);
-               return nullptr;
-       }
+
        ndpIndicationResp->service_name_len = len;
        memcpy(&ndpIndicationResp->service_name,
                        config->serviceName, ndpIndicationResp->service_name_len);
index 99932c602773ba75731bfc3002c4e3bce2e6f69c..ad50c1979563969985029d1ec26f5811a859d5ea 100644 (file)
@@ -42,10 +42,15 @@ void NanPeerManager::add(uint32_t peerId, NanPeer *peer)
 NanPeer *NanPeerManager::createPeer(uint32_t requestorId, const unsigned char *addr)
 {
        uint32_t peerId = getNextPeerId();
-       NanPeer *peer = new NanPeer(peerId, requestorId, addr);
-       if (peer != nullptr)
+
+       try {
+               NanPeer *peer = new NanPeer(peerId, requestorId, addr);
                add(peerId, peer);
-       return peer;
+               return peer;
+       } catch (std::bad_alloc& e) {
+               NAN_LOGE("Out of memory");
+               return nullptr;
+       }
 }
 
 NanPeer *NanPeerManager::findPeer(uint32_t peerId)
index 329101e443689c4d22dccb5ec89749aee1bcc7b3..9f9b14115fc8b856fedca3c95db4cabcaa4a097e 100644 (file)
@@ -195,12 +195,13 @@ NanError NanServiceProvider::enable(std::shared_ptr<EnableConfig> config)
        int clientId = client->getClientId();
        NAN_LOGD("Enable in client %d", clientId);
 
-       NanCommand *cmd = new NanEnableCommand(config, clientId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanEnableCommand(config, clientId);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
 
        return NAN_ERROR_NONE;
 }
@@ -227,19 +228,19 @@ NanError NanServiceProvider::disable(std::shared_ptr<DisableConfig> config, int
        // If it is already disabled, return error.
 
        if (mClientManager.hasNoClient()) {
-               NanCommand *cmd = new NanDisableCommand(config, clientId);
-               if (cmd == nullptr) {
+               try {
+                       NanCommand *cmd = new NanDisableCommand(config, clientId);
+                       mDataPathManager.clear();       // Should be already done
+                       mPeerManager.clear();
+                       mCommandQueue.clear();          // Should be already done
+                       //deleteAllNanInterfaces();
+
+                       scheduleCommand(cmd);
+                       setEnabled(false);
+               } catch (std::bad_alloc& e) {
                        NAN_LOGE("Out of memory");
                        return NAN_ERROR_MEMORY;
                }
-
-               mDataPathManager.clear();       // Should be already done
-               mPeerManager.clear();
-               mCommandQueue.clear();          // Should be already done
-               //deleteAllNanInterfaces();
-
-               scheduleCommand(cmd);
-               setEnabled(false);
        }
 
        return NAN_ERROR_NONE;
@@ -255,14 +256,14 @@ NanError NanServiceProvider::publish(std::shared_ptr<PublishConfig> config, int
        }
 
        config->logConfigurations();
-       NanCommand *cmd = new NanPublishCommand(config, clientId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanPublishCommand(config, clientId);
+               scheduleCommand(cmd);
+               return NAN_ERROR_NONE;
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
-
-       return NAN_ERROR_NONE;
 }
 
 NanError NanServiceProvider::updatePublish(std::shared_ptr<PublishConfig> config,
@@ -282,12 +283,13 @@ NanError NanServiceProvider::updatePublish(std::shared_ptr<PublishConfig> config
        }
 
        config->logConfigurations();
-       NanCommand *cmd = new NanUpdatePublishCommand(config, clientId, publishId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanUpdatePublishCommand(config, clientId, publishId);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
 
        return NAN_ERROR_NONE;
 }
@@ -311,13 +313,13 @@ NanError NanServiceProvider::cancelPublish(int clientId, uint16_t publishId)
 
        mCommandQueue.removeCommandsWithPubSubId(publishId);
 
-       NanCommand *cmd = new NanCancelPublishCommand(clientId, publishId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanCancelPublishCommand(clientId, publishId);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
-
        return NAN_ERROR_NONE;
 }
 
@@ -331,12 +333,13 @@ NanError NanServiceProvider::subscribe(std::shared_ptr<SubscribeConfig> config,
        }
 
        config->logConfigurations();
-       NanCommand *cmd = new NanSubscribeCommand(config, clientId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanSubscribeCommand(config, clientId);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
 
        return NAN_ERROR_NONE;
 }
@@ -358,12 +361,13 @@ NanError NanServiceProvider::updateSubscribe(std::shared_ptr<SubscribeConfig> co
        }
 
        config->logConfigurations();
-       NanCommand *cmd = new NanUpdateSubscribeCommand(config, clientId, subscribeId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanUpdateSubscribeCommand(config, clientId, subscribeId);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
 
        return NAN_ERROR_NONE;
 }
@@ -387,14 +391,14 @@ NanError NanServiceProvider::cancelSubscribe(int clientId, uint16_t subscribeId)
 
        mCommandQueue.removeCommandsWithPubSubId(subscribeId);
 
-       NanCommand *cmd = new NanCancelSubscribeCommand(clientId, subscribeId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanCancelSubscribeCommand(clientId, subscribeId);
+               scheduleCommand(cmd);
+               return NAN_ERROR_NONE;
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
-
-       return NAN_ERROR_NONE;
 }
 
 NanError NanServiceProvider::followup(std::shared_ptr<FollowupConfig> config,
@@ -419,12 +423,13 @@ NanError NanServiceProvider::followup(std::shared_ptr<FollowupConfig> config,
 
        config->logConfigurations();
 
-       NanCommand *cmd = new NanTransmitFollowupCommand(config, clientId, pubSubId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanTransmitFollowupCommand(config, clientId, pubSubId);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
 
        return NAN_ERROR_NONE;
 }
@@ -433,25 +438,24 @@ void NanServiceProvider::createDataPathInterface(std::string interface)
 {
        NAN_LOGI("Create Command for [CREATE_DP_INTERFACE] interface: %s", interface.c_str());
 
-       NanCommand *cmd = new NanCreateInterfaceCommand(interface);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanCreateInterfaceCommand(interface);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
-               return;
        }
-       scheduleCommand(cmd);
-
 }
 
 void NanServiceProvider::deleteDataPathInterface(std::string interface)
 {
        NAN_LOGI("Create Command for [DELETE_DP_INTERFACE] interface: %s", interface.c_str());
-
-       NanCommand *cmd = new NanDeleteInterfaceCommand(interface);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanDeleteInterfaceCommand(interface);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return;
        }
-       scheduleCommand(cmd);
 }
 
 NanError NanServiceProvider::openDataPath(std::shared_ptr<DataPathConfig> config, int clientId, 
@@ -503,11 +507,13 @@ NanError NanServiceProvider::openDataPath(std::shared_ptr<DataPathConfig> config
        NanCommand *cmd = nullptr;
        if (role == NAN_DATA_PATH_INITIATOR) {
                NAN_LOGI("Create Command for [DATA_PATH_INITIATE]");
-               cmd = new NanDataPathRequestCommand(config, clientId, pubSubId, info);
-               if (cmd == nullptr) {
+               try {
+                       cmd = new NanDataPathRequestCommand(config, clientId, pubSubId, info);
+               } catch (std::bad_alloc& e) {
                        NAN_LOGE("Out of memory");
                        return NAN_ERROR_MEMORY;
                }
+
                scheduleCommand(cmd);
                info->setState(DataPathState::INITIATOR_WAIT_FOR_REQUEST_RESPONSE);
                mDataPathManager.startOpenDataPathTimer(info, client->getClientPath());
@@ -548,14 +554,14 @@ NanError NanServiceProvider::closeDataPath(std::shared_ptr<DataPathEndConfig> co
                return NAN_ERROR_INVALID_PARAMETER;
        }
 
-       NanCommand *cmd = new NanDataPathEndCommand(config, clientId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanDataPathEndCommand(config, clientId);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
 
-       scheduleCommand(cmd);
-
        // Do not remove dataPathInfo here.
        // It is going to be removed in receiveDataPathEndEvent() after getting 'END' event.
 
@@ -566,12 +572,13 @@ NanError NanServiceProvider::getCapabilities(void)
 {
        NAN_LOGI("Create Command for [CAPABILITIES]");
 
-       NanCommand *cmd = new NanGetCapabilities;
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanGetCapabilities;
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return NAN_ERROR_MEMORY;
        }
-       scheduleCommand(cmd);
 
        return NAN_ERROR_NONE;
 }
@@ -992,13 +999,13 @@ void NanServiceProvider::closeDataPathInternal(uint32_t dataPathId, int clientId
        std::shared_ptr<DataPathEndConfig> config = DataPathEndConfig::createDefaultConfig();
        config->dataPathId = dataPathId;
 
-       NanCommand *cmd = new NanDataPathEndCommand(config, clientId);
-       if (cmd == nullptr) {
+       try {
+               NanCommand *cmd = new NanDataPathEndCommand(config, clientId);
+               scheduleCommand(cmd);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return;
        }
-
-       scheduleCommand(cmd);
 }
 
 void NanServiceProvider::closeDataPathInternal(uint32_t dataPathId)
@@ -1446,9 +1453,10 @@ void NanServiceProvider::runDataPathResponseCommand(std::shared_ptr<DataPathConf
 {
        NAN_LOGI("Create Command for [DATA_PATH_RESPONSE] client: %p", client);
        RET_IF_NULL(client);
-
-       NanCommand *cmd = new NanDataPathResponseCommand(config, client->getClientId(), info);
-       if (cmd == nullptr) {
+       NanCommand *cmd;
+       try {
+               cmd = new NanDataPathResponseCommand(config, client->getClientId(), info);
+       } catch (std::bad_alloc& e) {
                NAN_LOGE("Out of memory");
                return;
        }