RDKEMW-21962 : ctrlm-main - Use of potentially dangerous function#263
Conversation
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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_typeis allocated withnewbut the error cleanup loop frees existing entries withg_free, which is a mismatched deallocator (undefined behavior). Usedeletefor 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);
There was a problem hiding this comment.
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 withg_free, but they are allocated withnewand later freed withdelete(see the normal cleanup loop at the end of the function). Usingg_freehere is a mismatched deallocator and is undefined behavior. Usedeletefor 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++) {
There was a problem hiding this comment.
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->secondis freed withg_free, but these entries are allocated withnew(and later released withdeleteat the end of the function). Mixingnew/deletewithmalloc/free(viag_free) is undefined behavior; usedeletehere 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;
}
No description provided.