Skip to content

RDKEMW-21962 : ctrlm-main - Use of potentially dangerous function#263

Merged
dwolaver merged 9 commits into
developfrom
feature/RDKEMW-21962_control_dangerous_function
Jul 23, 2026
Merged

RDKEMW-21962 : ctrlm-main - Use of potentially dangerous function#263
dwolaver merged 9 commits into
developfrom
feature/RDKEMW-21962_control_dangerous_function

Conversation

@dwolaver

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

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 RDKEMW-21962 in the ctrlm-main (Control Manager) plugin by replacing use of localtime() (non-thread-safe / potentially dangerous) with localtime_r() in telemetry/logging code paths.

Changes:

  • Updated RF4CE controller telemetry logging to use localtime_r() when formatting bind/unbind timestamps.
  • Updated database dump logging to use localtime_r() when formatting stored binding timestamps.
  • Updated controller status printing utilities to use localtime_r() when formatting various controller timestamps.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/rf4ce/ctrlm_rf4ce_controller.cpp Switches bind/unbind telemetry timestamp formatting from localtime() to localtime_r().
src/database/ctrlm_database.cpp Uses localtime_r() for printing stored binding time during DB dump.
src/ctrlm_utils.cpp Uses localtime_r() for formatting controller status timestamps (binding/last key/battery update).

Comment thread src/rf4ce/ctrlm_rf4ce_controller.cpp Outdated
Comment thread src/rf4ce/ctrlm_rf4ce_controller.cpp Outdated
Comment thread src/ctrlm_utils.cpp
Comment thread src/ctrlm_utils.cpp
Comment thread src/ctrlm_utils.cpp

Copilot AI left a comment

Copy link
Copy Markdown

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 9 out of 9 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

src/rf4ce/ctrlm_rf4ce_network.cpp:2258

  • new_type is allocated with new but the error cleanup loop frees existing entries with g_free, which is a mismatched deallocator (undefined behavior). Use delete for these entries to match the allocation and the normal cleanup path later in the function.
         controller_type_details_t *new_type = new(std::nothrow) controller_type_details_t();
         if(new_type==NULL){
            XLOGD_ERROR("error on allocating.. aborting" );
            // if we could not malloc memory then we need to free our current mallocs and get out
            for (type_it = controller_types.begin(); type_it != controller_types.end(); type_it++) {

src/factory/ctrlmf_audio_capture.cpp:55

  • This file now uses std::nothrow, which is declared in <new>. Add an explicit #include <new> to avoid relying on transitive includes (which can break builds depending on toolchain/standard library).
bool ctrlmf_audio_capture_init(uint32_t audio_frame_size, bool *has_local_mic_tap) {

   g_audio_cap.obj_ctrlm = new(std::nothrow) Iarm::ControlManager::ctrlm_iarm_client_control_manager_t;

   if(g_audio_cap.obj_ctrlm == NULL) {
      XLOGD_ERROR("out of memory");
      return(false);

Comment thread src/thunder/ctrlm_thunder_plugin_powermanager.cpp
Comment thread src/factory/ctrlmf_audio_playback.cpp
Comment thread src/factory/ctrlmf_mic_test.cpp

Copilot AI left a comment

Copy link
Copy Markdown

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 9 out of 9 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/rf4ce/ctrlm_rf4ce_network.cpp:2258

  • In the allocation-failure cleanup path, controller_type_details_t* values are freed with g_free, but they are allocated with new and later freed with delete (see the normal cleanup loop at the end of the function). Using g_free here is a mismatched deallocator and is undefined behavior. Use delete for these entries as well.
         controller_type_details_t *new_type = new(std::nothrow) controller_type_details_t();
         if(new_type==NULL){
            XLOGD_ERROR("error on allocating.. aborting" );
            // if we could not malloc memory then we need to free our current mallocs and get out
            for (type_it = controller_types.begin(); type_it != controller_types.end(); type_it++) {

Comment thread src/rf4ce/ctrlm_rf4ce_network.cpp
Comment thread src/factory/ctrlmf_audio_capture.cpp

Copilot AI left a comment

Copy link
Copy Markdown

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 9 out of 9 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/rf4ce/ctrlm_rf4ce_network.cpp:2262

  • In the OOM cleanup path, type_it->second is freed with g_free, but these entries are allocated with new (and later released with delete at the end of the function). Mixing new/delete with malloc/free (via g_free) is undefined behavior; use delete here as well.
            // if we could not malloc memory then we need to free our current mallocs and get out
            for (type_it = controller_types.begin(); type_it != controller_types.end(); type_it++) {
               g_free(type_it->second);
               type_it->second = NULL;
            }

@dwolaver
dwolaver marked this pull request as ready for review July 20, 2026 19:13
@dwolaver
dwolaver requested a review from a team as a code owner July 20, 2026 19:13

@egalla204 egalla204 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.

approved for test

Copilot AI review requested due to automatic review settings July 23, 2026 18:38

Copilot AI left a comment

Copy link
Copy Markdown

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 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/rf4ce/ctrlm_rf4ce_network.cpp
@dwolaver
dwolaver merged commit 5906429 into develop Jul 23, 2026
11 checks passed
@dwolaver
dwolaver deleted the feature/RDKEMW-21962_control_dangerous_function branch July 23, 2026 19:16
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants