From 208a7dd17f3b49a37980ea8f084d57f8c35f5e92 Mon Sep 17 00:00:00 2001 From: echo-devim Date: Thu, 7 Jul 2022 17:12:53 +0200 Subject: [PATCH] Bug fixing possible null dereferences for launch point LaunchPointPtr is a pointer initialized by calling getByLaunchPointId. This function can return a nullptr value, thus LaunchPointPtr could be null. A check to ensure the validity of the pointer should be always performed before it is used. --- src/bus/client/DB8.cpp | 11 +++++++---- src/manager/PolicyManager.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/bus/client/DB8.cpp b/src/bus/client/DB8.cpp index 84d4991..27b6471 100644 --- a/src/bus/client/DB8.cpp +++ b/src/bus/client/DB8.cpp @@ -210,13 +210,16 @@ bool DB8::onFind(LSHandle* sh, LSMessage* message, void* context) } launchPoint = LaunchPointList::getInstance().getByLaunchPointId(launchPointId); + if (launchPoint == nullptr) { + Logger::warning(getClassName(), __FUNCTION__, "Cannot find launch point"); + DB8::getInstance().deleteLaunchPoint(launchPointId); + continue; + } if (type == "default") { launchPoint->setDatabase(results[i]); } else if (type == "bookmark") { - if (launchPoint == nullptr) { - launchPoint = LaunchPointList::getInstance().createBootmarkByDB(appDesc, results[i]); - LaunchPointList::getInstance().add(launchPoint); - } + launchPoint = LaunchPointList::getInstance().createBootmarkByDB(appDesc, results[i]); + LaunchPointList::getInstance().add(launchPoint); } } Logger::info(getInstance().getClassName(), __FUNCTION__, "Complete to sync DB8"); diff --git a/src/manager/PolicyManager.cpp b/src/manager/PolicyManager.cpp index 098ad13..98fa2ad 100644 --- a/src/manager/PolicyManager.cpp +++ b/src/manager/PolicyManager.cpp @@ -165,6 +165,12 @@ void PolicyManager::onCloseForRemove(LunaTaskPtr lunaTask) { lunaTask->setSuccessCallback(boost::bind(&PolicyManager::onReplyWithoutIds, this, boost::placeholders::_1)); LaunchPointPtr launchPoint = LaunchPointList::getInstance().getByLaunchPointId(lunaTask->getLaunchPointId()); + if (launchPoint == nullptr) { + Logger::warning(getClassName(), __FUNCTION__, "Cannot find launch point"); + lunaTask->setErrCodeAndText(ErrCode_GENERAL, "Cannot find launch point"); + lunaTask->error(lunaTask); + return; + } switch(launchPoint->getType()) { case LaunchPointType::LaunchPoint_DEFAULT: