Skip to content

RDKEMW-12282: Fix Coverity identified issues - dobby#408

Open
dkumar798 wants to merge 37 commits intordkcentral:topic/RDKEMW-13941from
dkumar798:topic/RDKEMW-12282
Open

RDKEMW-12282: Fix Coverity identified issues - dobby#408
dkumar798 wants to merge 37 commits intordkcentral:topic/RDKEMW-13941from
dkumar798:topic/RDKEMW-12282

Conversation

@dkumar798
Copy link
Copy Markdown

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/recipes-containers/dobby/dobby.inc) must be modified to support the changes in this PR (beyond updating SRC_REV)

Copilot AI review requested due to automatic review settings February 6, 2026 04:02
Copy link
Copy Markdown

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 pull request addresses Coverity static analysis issues identified in the Dobby container runtime. The changes primarily focus on fixing concurrency issues, resource management problems, TOCTOU (time-of-check-time-of-use) vulnerabilities, buffer overflows, and other code quality issues.

Changes:

  • Fixed concurrency and thread safety issues by adding proper mutex locking, using atomic variables where appropriate, and ensuring locks are released before callbacks
  • Addressed resource leaks and proper initialization of member variables across multiple plugins
  • Replaced TOCTOU-prone patterns (access/stat followed by open/opendir) with direct operations
  • Fixed buffer overflow vulnerabilities by using strncpy instead of strcpy and adding bounds checking
  • Added exception handling in destructors and main functions to prevent unexpected terminations
  • Fixed iterator invalidation issues and improved error handling throughout the codebase

Reviewed changes

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

Show a summary per file
File Description
utils/source/DobbyUtils.cpp Added mutex locking for thread-safe access to metadata maps in const methods
utils/include/DobbyUtils.h Made metadata mutex mutable to allow locking in const methods
settings/source/Settings.cpp Fixed resource leak by calling wordfree and corrected indentation
rdkPlugins/Storage/source/RefCountFile.cpp Added overflow checks for reference counter and improved error handling
rdkPlugins/Storage/source/LoopMountDetails.cpp Prevented double close by resetting fd after close
rdkPlugins/Storage/source/DynamicMountDetails.cpp Fixed file creation logic and improved error handling
rdkPlugins/OOMCrash/source/OOMCrashPlugin.cpp Improved file operation error handling and fixed indentation
rdkPlugins/Networking/source/NetworkingPlugin.cpp Initialized mPluginData pointer to nullptr
rdkPlugins/Networking/source/NetworkSetup.cpp Fixed iterator usage to avoid dangling iterator issues
rdkPlugins/Networking/source/IPAllocator.cpp Replaced stat with opendir to fix TOCTOU vulnerability
rdkPlugins/Minidump/source/AnonymousFile.cpp Fixed file size check and corrected indentation
rdkPlugins/Logging/source/FileSink.cpp Initialized mFileSizeLimit member variable
rdkPlugins/IONMemory/source/IonMemoryPlugin.cpp Initialized mPluginData pointer to nullptr
rdkPlugins/HttpProxy/source/HttpProxyPlugin.cpp Initialized mPluginData pointer to nullptr
rdkPlugins/AppServices/source/AppServicesRdkPlugin.cpp Initialized mPluginConfig pointer to nullptr
plugins/OpenCDM/source/OpenCDMPlugin.cpp Replaced access() with direct operations and improved error handling
plugins/MulticastSockets/source/MulticastSocketsPlugin.cpp Added socket validation, fixed format specifier, and used move semantics
plugins/EthanLog/source/EthanLogLoop.cpp Added lock guard for thread-safe access to mClients
plugins/EthanLog/source/EthanLogClient.cpp Added bounds checking to prevent buffer overflow
plugins/EthanLog/client/cat/ethanlog-cat.cpp Fixed buffer overflow check and changed mBufferOffset type to size_t
plugins/Common/source/ServiceMonitor.cpp Improved lock management for state change notifications
pluginLauncher/tool/source/Main.cpp Added missing break statement in switch case
pluginLauncher/lib/source/DobbyRdkPluginUtils.cpp Initialized exitStatus member variable
pluginLauncher/lib/source/DobbyRdkPluginManager.cpp Added scandir error handling and removed incorrect close call
pluginLauncher/lib/include/DobbyRdkPluginUtils.h Added lock guard for thread-safe access to annotations
ipcUtils/source/DobbyIpcBus.cpp Fixed lock guard scoping
daemon/process/source/Main.cpp Added exception handling in main and missing break statement
daemon/lib/source/include/DobbyWorkQueue.h Changed counters to atomic types
daemon/lib/source/DobbyWorkQueue.cpp Added missing lock guard
daemon/lib/source/DobbyStats.cpp Fixed format specifier for long long type
daemon/lib/source/DobbyManager.cpp Fixed iterator invalidation, lambda captures, and added exception annotations
daemon/lib/source/DobbyLogger.cpp Added exception handling in destructor and replaced strcpy with strncpy
daemon/lib/source/DobbyLogRelay.cpp Initialized member variables and replaced strcpy with strncpy
daemon/lib/source/DobbyContainer.cpp Initialized mRestartCount member variable
daemon/lib/source/Dobby.cpp Improved error handling for reply sends and removed unreachable code
client/tool/source/Main.cpp Fixed TOCTOU vulnerability, added missing break, and lock guards
client/lib/source/DobbyProxy.cpp Fixed lock guard scoping
bundle/tool/source/Main.cpp Added exception handling in main and missing break statement
bundle/lib/source/DobbyTemplate.cpp Fixed potential use-after-unlock by copying pointer before unlock
bundle/lib/source/DobbySpecConfig.cpp Initialized variables and added lock guard
bundle/lib/source/DobbyRootfs.cpp Replaced access with open to fix TOCTOU vulnerability
bundle/lib/source/DobbyConfig.cpp Added lock guard and fixed indentation
bundle/lib/source/DobbyBundleConfig.cpp Added lock guards for const methods and fixed indentation
bundle/lib/include/DobbyBundleConfig.h Fixed indentation
AppInfrastructure/ReadLine/source/ReadLine.cpp Fixed escape sequence in format string
AppInfrastructure/Public/Common/Notifier.h Removed extra unlock and added Coverity annotation
AppInfrastructure/IpcService/source/sdbus/SDBusIpcService.cpp Fixed integer overflow in timeout calculations
AppInfrastructure/Common/source/Timer.cpp Added exception handling in destructor
AppInfrastructure/Common/source/ThreadedDispatcher.cpp Improved lock management and fixed indentation
AppInfrastructure/Common/include/IDGenerator.h Replaced rand() with random_device for better randomness
AppInfrastructure/Common/include/ConditionVariable.h Removed unreachable return statement

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

Copilot AI review requested due to automatic review settings February 12, 2026 09:24
Copy link
Copy Markdown

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

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


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

Copilot AI review requested due to automatic review settings February 12, 2026 10:26
Copy link
Copy Markdown

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

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

Comments suppressed due to low confidence (1)

rdkPlugins/Minidump/source/AnonymousFile.cpp:140

  • getFileSize() can return a negative value on error (ftell returns -1). The new fileSize <= 0 check treats this as success and returns true, silently skipping error handling. Handle fileSize < 0 as a failure (log and return false), and only treat fileSize == 0 as the empty-file success case.

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

Copilot AI review requested due to automatic review settings February 12, 2026 11:17
Copy link
Copy Markdown

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

Copilot reviewed 50 out of 51 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

rdkPlugins/Minidump/source/AnonymousFile.cpp:140

  • getFileSize() returns -1 on ftell() failure, but copyContentTo() now treats fileSize <= 0 as success and returns true. That means real errors (e.g. ftell/fseek failures) will be silently ignored and the minidump won’t be persisted. Distinguish empty (== 0) from error (< 0) and return false (or log + fail) on error.

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

Copy link
Copy Markdown

@Sasikumartech Sasikumartech left a comment

Choose a reason for hiding this comment

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

approved

@ks734 ks734 changed the base branch from develop to topic/RDKEMW-13941 March 23, 2026 06:14
if (path.length() >= sizeof(address.sun_path))
{
AI_LOG_ERROR("Socket path too long: %s", path.c_str());
return -1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coverity Issue - Resource leak

Handle variable "sockFd" going out of scope leaks the handle.

High Impact, CWE-404
RESOURCE_LEAK

if (path.length() >= sizeof(address.sun_path))
{
AI_LOG_ERROR("Socket path too long: %s", path.c_str());
return -1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coverity Issue - Resource leak

Handle variable "sockFd" going out of scope leaks the handle.

High Impact, CWE-404
RESOURCE_LEAK

Copilot AI review requested due to automatic review settings March 23, 2026 11:47
Copy link
Copy Markdown

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

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


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

Comment on lines 575 to +579
if (ret < 0)
break;

numFields += ret;
if (ret > 0 && numFields + ret <= maxFields && numFields + ret > 0)
numFields += ret;
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

fields is declared as struct iovec fields[maxFields + 2], and processPid() can return 2 fields. The new guard compares against maxFields (16), so when numFields == 15 and ret == 2 it will not advance numFields even though two iov entries were written. This can lead to subsequent fields overwriting prior entries and sd_journal_sendv() being called with an incorrect numFields. Use the actual capacity (e.g., std::size(fields)) for the bounds check and treat “insufficient remaining space for ret fields” as a hard parse failure (break/return) rather than silently skipping the increment.

Copilot uses AI. Check for mistakes.
Comment on lines +163 to +180
if (prepareOk && !isDir)
{
// If mounting a file, make sure a file with the same name
// exists at the desination path prior to bind mounting.
// Otherwise the bind mount may fail if the destination path
// filesystem is read-only.
// Creating the file first ensures an inode exists for the
// bind mount to target.
int fd = open(targetPath.c_str(), O_CLOEXEC | O_CREAT | O_WRONLY, 0644);
if (fd >= 0)
{
if (isDir)
{
success = true;
}
else
{
// If mounting a file, make sure a file with the same name
// exists at the desination path prior to bind mounting.
// Otherwise the bind mount may fail if the destination path
// filesystem is read-only.
// Creating the file first ensures an inode exists for the
// bind mount to target.
int fd = open(targetPath.c_str(), O_RDONLY | O_CREAT, 0644);
if ((fd == 0) || (errno == EEXIST))
{
close(fd);
success = true;
}
else
{
AI_LOG_SYS_ERROR(errno, "failed to open or create destination '%s'", targetPath.c_str());
}
}
close(fd);
// file creation succeeded (or opened existing file), continue
}
else
{
AI_LOG_SYS_ERROR(errno, "failed to create mount destination path '%s' in storage plugin", targetPath.c_str());
AI_LOG_SYS_ERROR(errno, "failed to open or create destination '%s'", targetPath.c_str());
prepareOk = false;
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

For file bind mounts, the destination is opened with O_CREAT | O_WRONLY. If the destination file already exists but is not writable (common if the rootfs is read-only), this open will fail even though the code comment says it only needs an inode to exist for the bind mount. Prefer opening with read access (e.g., O_RDONLY | O_CREAT | O_CLOEXEC) or another non-writing approach so existing read-only files don’t cause mount preparation to fail.

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.

6 participants