Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible null dereferences for launchPoint #3

Open
echo-devim opened this issue Jul 7, 2022 · 0 comments
Open

Possible null dereferences for launchPoint #3

echo-devim opened this issue Jul 7, 2022 · 0 comments

Comments

@echo-devim
Copy link

I noticed that the function LaunchPointList::getByLaunchPointId can return a nullptr that is not always checked.

LaunchPointPtr LaunchPointList::getByLaunchPointId(const string& launchPointId)
{
if (launchPointId.empty())
return nullptr;
for (auto it = m_list.begin(); it != m_list.end(); ++it) {
if ((*it)->getLaunchPointId() == launchPointId) {
return *it;
}
}
return nullptr;
}

Consider the following lines:

void PolicyManager::onCloseForRemove(LunaTaskPtr lunaTask)
{
lunaTask->setSuccessCallback(boost::bind(&PolicyManager::onReplyWithoutIds, this, boost::placeholders::_1));
LaunchPointPtr launchPoint = LaunchPointList::getInstance().getByLaunchPointId(lunaTask->getLaunchPointId());
switch(launchPoint->getType()) {

The variable launchPoint could be null, but getType() member function is called without any check.
I found the same issue in DB8::onFind function.

sam/src/bus/client/DB8.cpp

Lines 212 to 220 in af986e6

launchPoint = LaunchPointList::getInstance().getByLaunchPointId(launchPointId);
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);
}
}

if type is equal to default then launchPoint is not checked. I also noticed that some functions in this class like onFind, onPutKind and onPutPermissions return always true.

The same function (getByLaunchPointId) when used in other pieces of code is checked.
Below there is an example:

RunningAppPtr RunningAppList::createByLaunchPointId(const string& launchPointId)
{
LaunchPointPtr launchPoint = LaunchPointList::getInstance().getByLaunchPointId(launchPointId);
if (launchPoint == nullptr) {
Logger::warning(getClassName(), __FUNCTION__, "Cannot find launchPoint");
return nullptr;
}

I'm not sure if the check is missing because in these cases there is always a valid launchPointId. Maybe it's better to always perform the check before using the variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant