Skip to content

RDKEMW-61972: Fix Coverity defects (3 files) - #548

Open
rdkdevpilot wants to merge 3 commits into
developfrom
topic/RDKEMW-61972
Open

rdkdevpilot wants to merge 3 commits into
developfrom
topic/RDKEMW-61972

Conversation

@rdkdevpilot

Copy link
Copy Markdown

Automated Fix for Coverity Defects

Triggered by: dev-user

Fixed Files

File Line(s) CIDs Checker Types Description
src/hostif/parodusClient/pal/libpd.cpp L163 52614 BAD_CHECK_OF_WAIT_COND Data race condition
src/hostif/parodusClient/pal/webpa_adapter.cpp L119 59455 DEADCODE 'Constant' variable guards dead code
src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp L475 52622 MISSING_LOCK Data race condition

Fix Summaries

src/hostif/parodusClient/pal/libpd.cpp

The fix correctly addresses the BAD_CHECK_OF_WAIT_COND defect by replacing if with while around the pthread_cond_timedwait call, ensuring the predicate is re-checked after spurious wakeups as required by POSIX. The change is minimal (single keyword), does not introduce new defects, and preserves all existing logic including the mutex lock/unlock pattern and the outer loop behavior.

src/hostif/parodusClient/pal/webpa_adapter.cpp

The fix correctly addresses the DEADCODE defect by adding a call to getnotifyparamList() before the NULL check on line 117. This populates the notifyparameters pointer, making the previously unreachable code block (lines 118-157) now reachable. The fix is minimal, adding only the necessary function call to resolve the defect without introducing new bugs or breaking existing logic.

src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp

The fix correctly adds std::lock_guardstd::mutex lg(m_mutex) in checkForUpdates() before accessing shared member variables (curNumOfIPInterface, curNumOfInterfaceIPv4Addresses, etc.), directly addressing the MISSING_LOCK data race defect. The change is minimal and does not break existing logic. The second 'lg' declaration at line 537 is inside a #ifdef HAVE_VALUE_CHANGE_EVENT block that is never compiled (the macro is commented out at line 34), so there is no duplicate variable name conflict.

Defect ID: 448f8b44-8542-4705-a175-0d33a5413c23
Defect ID: f0cebec9-68aa-41bc-84a9-1100192c51c3
Defect ID: 739ee7d9-b8d2-4951-ad2d-27c4b2da335c

Copilot AI left a comment

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.

🟡 Changes recommended

The new while loop around pthread_cond_timedwait() can busy-loop on timeout, and checkForUpdates() introduces a compile-time redeclaration risk when HAVE_VALUE_CHANGE_EVENT is enabled.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR aims to address three Coverity-reported defects in the TR-069 host interface codebase, focusing on condition-variable usage, dead code reachability, and missing locking around shared state.

Changes:

  • libpd.cpp: Switches a condition-variable wait guard from if to while in the Parodus receive thread.
  • webpa_adapter.cpp: Calls getnotifyparamList() so the initial notify list logic becomes reachable.
  • hostIf_IPClient_ReqHandler.cpp: Adds a mutex guard in checkForUpdates() to protect shared counters used for add/remove event generation.
File summaries
File Description
src/hostif/parodusClient/pal/webpa_adapter.cpp Populates notify parameter list so initialization logic can execute.
src/hostif/parodusClient/pal/libpd.cpp Adjusts pthread condvar wait loop to satisfy Coverity’s wait-condition checking expectation.
src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp Adds locking around shared state used during update/event checks.
Review details

Suppressed comments (1)

src/hostif/parodusClient/pal/libpd.cpp:165

  • The new while (!exit_parodus_recv.load()) loop around pthread_cond_timedwait will spin indefinitely on ETIMEDOUT because currTime is not updated and the loop never breaks on timeout/error. After the first timeout, subsequent timedwait calls will immediately return ETIMEDOUT, causing a busy loop while holding parodus_lock until stop_parodus_recv_wait() sets the exit flag.
                while (!exit_parodus_recv.load())
            {
                int wait_ret = pthread_cond_timedwait(&parodus_cond, &parodus_lock,&currTime);
                if(wait_ret == ETIMEDOUT)
                {
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

memset(&msgData,0,sizeof(msgData));

int interfaceNumberOfEntries = 0;
std::lock_guard<std::mutex> lg (m_mutex);
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Code Coverage Summary

                                        Total:|62.4%  2813|64.8% 247|    -    0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants