Skip to content

Possible null dereferences for launchPoint #3

@echo-devim

Description

@echo-devim

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions