Skip to content

Conversation

@dkumar798
Copy link

@dkumar798 dkumar798 commented Jan 13, 2026

Description

RDKEMW-12282: Fix Coverity identified issues - dobby

If there is a corresponding JIRA ticket, please ensure it is in the title of the PR.

Test Procedure

How to test this PR (if applicable)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other (doesn't fit into the above categories - e.g. documentation updates)

Requires Bitbake Recipe changes?

  • The base Bitbake recipe (meta-rdk-ext/recipes-containers/dobby/dobby.bb) must be modified to support the changes in this PR (beyond updating SRC_REV)

@dkumar798 dkumar798 marked this pull request as draft January 13, 2026 11:32
@dkumar798 dkumar798 marked this pull request as ready for review January 23, 2026 03:14
@ssitar583 ssitar583 requested a review from Copilot January 23, 2026 05:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a broad set of Coverity findings across Dobby by tightening thread-safety, fixing resource-handling edge cases, and hardening error paths.

Changes:

  • Add/adjust mutex/atomic usage to fix data races and uninitialized state warnings.
  • Fix resource cleanup and error-path correctness (fd/wordexp/scandir/remove/chmod, etc.).
  • Improve defensive checks (bounds/overflow) and a few logging/formatting issues.

Reviewed changes

Copilot reviewed 50 out of 50 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
utils/source/DobbyUtils.cpp Adds locking around metadata getters to avoid data races.
utils/include/DobbyUtils.h Makes metadata mutex mutable to support const getters locking.
settings/source/Settings.cpp Frees wordexp_t on error path to avoid leaks.
rdkPlugins/Storage/source/RefCountFile.cpp Adds overflow/error checks in refcount increment.
rdkPlugins/Storage/source/LoopMountDetails.cpp Prevents double-close by resetting fd after close.
rdkPlugins/Storage/source/DynamicMountDetails.cpp Refactors mount destination preparation and cleanup logic.
rdkPlugins/OOMCrash/source/OOMCrashPlugin.cpp Simplifies crash file removal and fixes file creation logging/close.
rdkPlugins/Networking/source/NetworkingPlugin.cpp Initializes plugin member pointer to nullptr.
rdkPlugins/Networking/source/NetworkSetup.cpp Uses operator[] for ruleset insertion to avoid invalid iterators.
rdkPlugins/Networking/source/IPAllocator.cpp Reworks directory existence/creation logic for IP store.
rdkPlugins/Minidump/source/AnonymousFile.cpp Treats non-positive file size as invalid/empty with clearer logging.
rdkPlugins/Logging/source/FileSink.cpp Initializes file size limit to avoid uninitialized use.
rdkPlugins/IONMemory/source/IonMemoryPlugin.cpp Initializes plugin member pointer to nullptr.
rdkPlugins/HttpProxy/source/HttpProxyPlugin.cpp Initializes plugin member pointer to nullptr.
rdkPlugins/AppServices/source/AppServicesRdkPlugin.cpp Initializes plugin config pointer to nullptr.
plugins/OpenCDM/source/OpenCDMPlugin.cpp Removes TOCTOU patterns; makes mounting conditional on chmod/chown success; checks addMount return.
plugins/MulticastSockets/source/MulticastSocketsPlugin.cpp Adds fd error checks; fixes env formatting; uses move on push_back.
plugins/EthanLog/source/EthanLogLoop.cpp Locks around client list clear for thread-safety.
plugins/EthanLog/source/EthanLogClient.cpp Adds bounds checks for field parsing to prevent overruns.
plugins/EthanLog/client/cat/ethanlog-cat.cpp Hardens buffer offset type/checks and fixes switch fallthrough.
plugins/Common/source/ServiceMonitor.cpp Removes explicit unlocks around callbacks/timer path.
pluginLauncher/tool/source/Main.cpp Fixes switch fallthrough in argument parsing.
pluginLauncher/lib/source/DobbyRdkPluginUtils.cpp Initializes exitStatus to a known value in constructors.
pluginLauncher/lib/source/DobbyRdkPluginManager.cpp Adds scandir failure handling and avoids redundant fd close.
pluginLauncher/lib/include/DobbyRdkPluginUtils.h Makes getAnnotations thread-safe by locking and returning a copy.
ipcUtils/source/DobbyIpcBus.cpp Removes redundant manual unlock before notifying/joining.
daemon/process/source/Main.cpp Wraps main in try/catch; fixes parseArgs switch fallthrough.
daemon/lib/source/include/DobbyWorkQueue.h Converts counters/flags to atomics.
daemon/lib/source/DobbyWorkQueue.cpp Adds locking in postWork path for same-thread enqueue.
daemon/lib/source/DobbyStats.cpp Fixes PID logging format/cast.
daemon/lib/source/DobbyManager.cpp Refactors shutdown cleanup iteration; fixes lambda capture/move behavior in hibernation path; adds Coverity annotation.
daemon/lib/source/DobbyLogger.cpp Wraps destructor in try/catch; replaces unsafe strcpy with strncpy.
daemon/lib/source/DobbyLogRelay.cpp Initializes members; replaces unsafe strcpy with strncpy.
daemon/lib/source/DobbyContainer.cpp Initializes restart count member.
daemon/lib/source/Dobby.cpp Improves error handling on async work/reply paths.
client/tool/source/Main.cpp Adds locking around promise fulfillment; removes TOCTOU by using opendir-first approach; fixes parseArgs fallthrough.
client/lib/source/DobbyProxy.cpp Removes redundant manual unlock before notifying/joining.
bundle/tool/source/Main.cpp Wraps main in try/catch; fixes parseArgs fallthrough.
bundle/lib/source/DobbyTemplate.cpp Fixes instance return after unlock; corrects prettyPrint whitespace stripping behavior.
bundle/lib/source/DobbySpecConfig.cpp Initializes vars and adds lock around spec version use.
bundle/lib/source/DobbyRootfs.cpp Replaces access() check with directory open + error-specific handling.
bundle/lib/source/DobbyConfig.cpp Adds lock around printCommand config access.
bundle/lib/source/DobbyBundleConfig.cpp Adds locks to several getters.
AppInfrastructure/ReadLine/source/ReadLine.cpp Fixes format string typo in error message.
AppInfrastructure/Public/Common/Notifier.h Adds Coverity annotation and removes redundant unlock.
AppInfrastructure/IpcService/source/sdbus/SDBusIpcService.cpp Prevents timeout multiplication overflow via casts.
AppInfrastructure/Common/source/Timer.cpp Adds try/catch around cancel in destructor.
AppInfrastructure/Common/source/ThreadedDispatcher.cpp Removes explicit unlocks; rewrites flush logic and adds locking in predicate.
AppInfrastructure/Common/include/IDGenerator.h Replaces rand() with random_device-based seed for initialization.
AppInfrastructure/Common/include/ConditionVariable.h Removes dead/unreachable return after throw.
Comments suppressed due to low confidence (1)

plugins/Common/source/ServiceMonitor.cpp:205

  • onReadyNotification invokes mStateChangeHandler while holding mLock (explicit unlock removed). This risks deadlock/re-entrancy issues and holds the mutex across user callback code. Capture any needed state under lock, unlock, then invoke the handler.
        // call the registered handler
        if (mStateChangeHandler)
            mStateChangeHandler(State::Ready);
    }
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 242 to 246
const std::string& DobbyBundleConfig::rootfsPath() const
{
std::lock_guard<std::mutex> locker(mLock);
return mRootfsPath;
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rootfsPath() returns a const reference to internal state. Locking inside the getter does not make the returned reference thread-safe after the function returns, and can give a false sense of safety. Prefer returning a copy (std::string) or require the caller to hold the lock for the lifetime of the reference.

Copilot uses AI. Check for mistakes.
Comment on lines +497 to +501
ContainerId id = it->first;
int32_t descriptor = it->second->descriptor;
AI_LOG_INFO("Stopping container %s", id.c_str());
++it;
locker.unlock();
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mLock is unlocked while iterating mContainers, but the iterator 'it' (advanced before unlock) is then reused after relocking. Another thread can erase the element that 'it' points to while the lock is released, leaving 'it' dangling and causing undefined behavior. Avoid carrying iterators across unlock; collect container IDs/descriptors to stop first, or restart iteration after relocking.

Copilot uses AI. Check for mistakes.
Comment on lines +35 to +38
try {
cancel();
} catch (const std::exception& e) {
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timer::~Timer() catches std::exception but ignores it (empty catch block), which can hide real failures during destruction. Either remove the try/catch (cancel() doesn't appear to throw here) or at least log the exception so failures aren't silently swallowed.

Suggested change
try {
cancel();
} catch (const std::exception& e) {
}
cancel();

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

1 participant