-
Notifications
You must be signed in to change notification settings - Fork 3
Fix/static analysis issues #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
8e79b32
0aca397
de6049a
b08cf08
7a41184
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * If not stated otherwise in this file or this component's Licenses.txt file the | ||
|
Check failure on line 2 in Miracast/MiracastPlayer/Generic/MiracastGstPlayer.cpp
|
||
| * following copyright and licenses apply: | ||
| * | ||
| * Copyright 2023 RDK Management | ||
|
|
@@ -37,7 +37,11 @@ | |
| { | ||
| if (m_GstPlayer == nullptr) | ||
| { | ||
| m_GstPlayer = new MiracastGstPlayer(); | ||
| m_GstPlayer = new (std::nothrow) MiracastGstPlayer(); | ||
| if (m_GstPlayer == nullptr) { | ||
| MIRACASTLOG_ERROR("Failed to allocate MiracastGstPlayer"); | ||
| return nullptr; | ||
| } | ||
| } | ||
| return m_GstPlayer; | ||
| } | ||
|
|
@@ -114,7 +118,7 @@ | |
| if (( nullptr != m_video_sink ) && ( 0 < m_video_rect_st.width ) && ( 0 < m_video_rect_st.height )) | ||
| { | ||
| char rectString[64]; | ||
| sprintf(rectString,"%d,%d,%d,%d", m_video_rect_st.startX, m_video_rect_st.startY, | ||
| snprintf(rectString, sizeof(rectString), "%d,%d,%d,%d", m_video_rect_st.startX, m_video_rect_st.startY, | ||
| m_video_rect_st.width, m_video_rect_st.height); | ||
| g_object_set(G_OBJECT(m_video_sink), "window-set", rectString, nullptr); | ||
| } | ||
|
|
@@ -723,7 +727,7 @@ | |
| GstStateChangeReturn ret; | ||
| GstBus *bus = nullptr; | ||
| bool return_value = true; | ||
| m_customQueueHandle = new MessageQueue(500,gstBufferReleaseCallback); | ||
| m_customQueueHandle = new (std::nothrow) MessageQueue(500,gstBufferReleaseCallback); | ||
|
|
||
| if (nullptr == m_customQueueHandle) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * If not stated otherwise in this file or this component's Licenses.txt file the | ||
|
Check failure on line 2 in Miracast/MiracastPlayer/RTSP/MiracastRTSPMsg.cpp
|
||
| * following copyright and licenses apply: | ||
| * | ||
| * Copyright 2023 RDK Management | ||
|
|
@@ -359,7 +359,7 @@ | |
| // Set the 1st to 3rd bits based on the value of skip_intervals | ||
| video_frame_control_support |= ((0x07 & st_video_fmt.st_h264_codecs.max_skip_intervals) << 1); // 1:3 bits for intervals | ||
|
|
||
| sprintf( video_format_buffer , | ||
| snprintf(video_format_buffer, sizeof(video_format_buffer), | ||
| "%02x %02x %02x %02x %08x %08x %08x %02x %04x %04x %02x ", | ||
| st_video_fmt.native, | ||
| st_video_fmt.preferred_display_mode_supported, | ||
|
|
@@ -384,7 +384,7 @@ | |
| } | ||
| else{ | ||
| memset( video_format_buffer , 0x00 , sizeof(video_format_buffer)); | ||
| sprintf( video_format_buffer , | ||
| snprintf(video_format_buffer, sizeof(video_format_buffer), | ||
| "%04x %04x", | ||
| st_video_fmt.st_h264_codecs.max_hres, | ||
| st_video_fmt.st_h264_codecs.max_vres ); | ||
|
|
@@ -447,7 +447,7 @@ | |
| } | ||
| memcpy(&m_wfd_audio_formats_st , &st_audio_fmt , sizeof(RTSP_WFD_AUDIO_FMT_STRUCT)); | ||
|
|
||
| sprintf( audio_format_buffer , | ||
| snprintf(audio_format_buffer, sizeof(audio_format_buffer), | ||
| "%s %08x %02x", | ||
| audio_format_str.c_str(), | ||
| st_audio_fmt.modes, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * If not stated otherwise in this file or this component's Licenses.txt file the | ||
|
Check failure on line 2 in Miracast/MiracastPlayer/RTSP/MiracastRTSPMsg.h
|
||
| * following copyright and licenses apply: | ||
| * | ||
| * Copyright 2023 RDK Management | ||
|
|
@@ -549,6 +549,7 @@ | |
|
|
||
| static std::string format_string(const char *fmt, const std::vector<const char *> &args) | ||
| { | ||
| const size_t MAX_FORMAT_SIZE = 8192; // 8KB limit | ||
| std::string result = fmt; | ||
| size_t arg_index = 0; | ||
| size_t arg_count = args.size(); | ||
|
|
@@ -557,6 +558,10 @@ | |
| size_t found = result.find("%s"); | ||
| if (found != std::string::npos) | ||
| { | ||
| // Check size limit before replacement | ||
| if (result.length() + strlen(args[arg_index]) > MAX_FORMAT_SIZE) { | ||
| break; // Prevent excessive size | ||
| } | ||
| result.replace(found, 2, args[arg_index]); | ||
| } | ||
| ++arg_index; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||
| * If not stated otherwise in this file or this component's Licenses.txt file the | ||||||||||||||||||||||||||||||||
|
Check failure on line 2 in Miracast/MiracastService/MiracastController.cpp
|
||||||||||||||||||||||||||||||||
| * following copyright and licenses apply: | ||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||
| * Copyright 2023 RDK Management | ||||||||||||||||||||||||||||||||
|
|
@@ -28,7 +28,7 @@ | |||||||||||||||||||||||||||||||
| MIRACASTLOG_TRACE("Entering..."); | ||||||||||||||||||||||||||||||||
| if (nullptr == m_miracast_ctrl_obj) | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| m_miracast_ctrl_obj = new MiracastController(); | ||||||||||||||||||||||||||||||||
| m_miracast_ctrl_obj = new (std::nothrow) MiracastController(); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| if (nullptr != m_miracast_ctrl_obj) | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| m_miracast_ctrl_obj->m_notify_handler = notifier; | ||||||||||||||||||||||||||||||||
|
|
@@ -93,7 +93,7 @@ | |||||||||||||||||||||||||||||||
| MiracastError ret_code = MIRACAST_OK; | ||||||||||||||||||||||||||||||||
| MIRACASTLOG_TRACE("Entering..."); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| m_controller_thread = new MiracastThread(CONTROLLER_THREAD_NAME, | ||||||||||||||||||||||||||||||||
| m_controller_thread = new (std::nothrow) MiracastThread(CONTROLLER_THREAD_NAME, | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| CONTROLLER_THREAD_STACK, | ||||||||||||||||||||||||||||||||
| CONTROLLER_MSGQ_COUNT, | ||||||||||||||||||||||||||||||||
| CONTROLLER_MSGQ_SIZE, | ||||||||||||||||||||||||||||||||
|
|
@@ -255,7 +255,7 @@ | |||||||||||||||||||||||||||||||
| std::size_t len = 0; | ||||||||||||||||||||||||||||||||
| unsigned char retry_count = 5; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| sprintf( sys_cls_file_ifidx , "/sys/class/net/%s/ifindex" , interface.c_str()); | ||||||||||||||||||||||||||||||||
| snprintf(sys_cls_file_ifidx, sizeof(sys_cls_file_ifidx), "/sys/class/net/%s/ifindex", interface.c_str()); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| std::ifstream ifIndexFile(sys_cls_file_ifidx); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -264,9 +264,7 @@ | |||||||||||||||||||||||||||||||
| return std::string(""); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| sprintf(command, "/sbin/udhcpc -v -i "); | ||||||||||||||||||||||||||||||||
| sprintf(command + strlen(command), "%s" , interface.c_str()); | ||||||||||||||||||||||||||||||||
| sprintf(command + strlen(command), " -s /etc/wifi_p2p/udhcpc.script 2>&1"); | ||||||||||||||||||||||||||||||||
| snprintf(command, sizeof(command), "/sbin/udhcpc -v -i %s -s /etc/wifi_p2p/udhcpc.script 2>&1", interface.c_str()); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| snprintf(command, sizeof(command), "/sbin/udhcpc -v -i %s -s /etc/wifi_p2p/udhcpc.script 2>&1", interface.c_str()); | |
| int written = snprintf(command, sizeof(command), "/sbin/udhcpc -v -i %s -s /etc/wifi_p2p/udhcpc.script 2>&1", interface.c_str()); | |
| if (written < 0 || written >= (int)sizeof(command)) { | |
| MIRACASTLOG_ERROR("Failed to format command string"); | |
| return std::string(""); | |
| } |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The buffer overflow protection silently discards data when the buffer is full. Consider logging a warning when remaining == 0 or when data is truncated, so that developers are aware that output is being lost. Additionally, the logic should break out of the loop once the buffer is full to avoid unnecessary iterations.
| data[data_len] = '\0'; | |
| } | |
| data[data_len] = '\0'; | |
| if (remaining == to_copy) { | |
| // The current line was exactly truncated to fit the buffer, check if next line would overflow | |
| continue; | |
| } | |
| } else { | |
| MIRACASTLOG_WARN("Buffer full while reading udhcpc output, truncating data."); | |
| break; | |
| } | |
| if (data_len >= sizeof(data) - 1) { | |
| MIRACASTLOG_WARN("Buffer full while reading udhcpc output, truncating data."); | |
| break; | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * If not stated otherwise in this file or this component's Licenses.txt file the | ||
|
Check failure on line 2 in Miracast/MiracastService/MiracastController.h
|
||
| * following copyright and licenses apply: | ||
| * | ||
| * Copyright 2023 RDK Management | ||
|
|
@@ -148,6 +148,8 @@ | |
| std::string m_localIp; | ||
| vector<DeviceInfo *> m_deviceInfoList; | ||
| GroupInfo *m_groupInfo; | ||
| // Mutex to protect shared boolean flags from data races | ||
| mutable std::mutex m_stateMutex; | ||
| bool m_connectionStatus; | ||
| bool m_p2p_backend_discovery{false}; | ||
| bool m_start_discovering_enabled{false}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| /** | ||
|
Check failure on line 1 in Miracast/MiracastService/MiracastServiceImplementation.cpp
|
||
| * If not stated otherwise in this file or this component's LICENSE | ||
| * file the following copyright and licenses apply: | ||
| * | ||
|
|
@@ -195,7 +195,7 @@ | |
|
|
||
| string query = "token=" + token; | ||
| Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T(SERVER_DETAILS))); | ||
| m_SystemPluginObj = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(SYSTEM_CALLSIGN_VER), (_T("MiracastService")), false, query); | ||
| m_SystemPluginObj = new (std::nothrow) WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(SYSTEM_CALLSIGN_VER), (_T("MiracastService")), false, query); | ||
| if (nullptr == m_SystemPluginObj) | ||
| { | ||
| MIRACASTLOG_ERROR("JSONRPC: %s: initialization failed", SYSTEM_CALLSIGN_VER); | ||
|
|
@@ -205,7 +205,7 @@ | |
| MIRACASTLOG_INFO("JSONRPC: %s: initialization ok", SYSTEM_CALLSIGN_VER); | ||
| } | ||
|
|
||
| m_WiFiPluginObj = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(WIFI_CALLSIGN_VER), (_T("MiracastService")), false, query); | ||
| m_WiFiPluginObj = new (std::nothrow) WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(_T(WIFI_CALLSIGN_VER), (_T("MiracastService")), false, query); | ||
| if (nullptr == m_WiFiPluginObj) | ||
| { | ||
| MIRACASTLOG_ERROR("JSONRPC: %s: initialization failed", WIFI_CALLSIGN_VER); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * If not stated otherwise in this file or this component's Licenses.txt file the | ||
|
Check failure on line 2 in Miracast/MiracastService/P2P/MiracastP2P.cpp
|
||
| * following copyright and licenses apply: | ||
| * | ||
| * Copyright 2023 RDK Management | ||
|
|
@@ -70,13 +70,17 @@ | |
| MIRACASTLOG_TRACE("Entering.."); | ||
| if (nullptr == m_miracast_p2p_obj) | ||
| { | ||
| m_miracast_p2p_obj = new MiracastP2P(); | ||
| m_miracast_p2p_obj = new (std::nothrow) MiracastP2P(); | ||
| if (nullptr != m_miracast_p2p_obj){ | ||
| ret_code = m_miracast_p2p_obj->Init(p2p_ctrl_iface); | ||
| if ( MIRACAST_OK != ret_code){ | ||
| destroyInstance(); | ||
| } | ||
| } | ||
| else { | ||
| MIRACASTLOG_ERROR("Failed to allocate MiracastP2P"); | ||
| ret_code = MIRACAST_P2P_INIT_FAILED; | ||
| } | ||
| } | ||
| error_code = ret_code; | ||
| MIRACASTLOG_TRACE("Exiting.."); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||
| /* | ||||||||||||||||||||
| * If not stated otherwise in this file or this component's Licenses.txt file the | ||||||||||||||||||||
|
Check failure on line 2 in Miracast/common/MiracastCommon.cpp
|
||||||||||||||||||||
| * following copyright and licenses apply: | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * Copyright 2023 RDK Management | ||||||||||||||||||||
|
|
@@ -250,9 +250,16 @@ | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| memset( buffer , 0x00 , sizeof(buffer)); | ||||||||||||||||||||
| size_t buffer_len = 0; | ||||||||||||||||||||
| while (getline(¤t_line_buffer, &len, popen_pipe_ptr) != -1) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| sprintf(buffer + strlen(buffer), "%s" , current_line_buffer); | ||||||||||||||||||||
| size_t remaining = sizeof(buffer) - buffer_len - 1; | ||||||||||||||||||||
| if (remaining > 0) { | ||||||||||||||||||||
| size_t to_copy = strnlen(current_line_buffer, remaining); | ||||||||||||||||||||
| memcpy(buffer + buffer_len, current_line_buffer, to_copy); | ||||||||||||||||||||
| buffer_len += to_copy; | ||||||||||||||||||||
| buffer[buffer_len] = '\0'; | ||||||||||||||||||||
|
||||||||||||||||||||
| buffer[buffer_len] = '\0'; | |
| buffer[buffer_len] = '\0'; | |
| if (to_copy == remaining && current_line_buffer[remaining - 1] != '\0' && current_line_buffer[remaining - 1] != '\n') { | |
| MIRACASTLOG_WARN("Buffer full, popen output truncated."); | |
| break; | |
| } | |
| } else { | |
| MIRACASTLOG_WARN("Buffer full, popen output truncated."); | |
| break; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ | |
| #include "WrapsMock.h" | ||
| #include "WorkerPoolImplementation.h" | ||
| #include "MiracastPlayerImplementation.h" | ||
| #include <sys/time.h> | ||
|
Check failure on line 36 in Tests/L1Tests/tests/test_MiracastPlayer.cpp
|
||
| #include <future> | ||
| #include <thread> | ||
|
|
||
|
|
@@ -120,7 +120,7 @@ | |
| struct tm *tm_info; | ||
| tm_info = localtime(&tv.tv_sec); | ||
|
|
||
| sprintf(time_str, ": %02d:%02d:%02d:%06ld", tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec, microseconds); | ||
| snprintf(time_str, sizeof(time_str), ": %02d:%02d:%02d:%06ld", tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec, microseconds); | ||
| } | ||
|
|
||
| void log( const char *func, const char *file, int line, int threadID,const char *format, ...) | ||
|
|
@@ -413,7 +413,7 @@ | |
| TEST_LOG("RTSP_SEND RESPONSE Messages"); | ||
| if (temp_buffer.find("%s") != std::string::npos) | ||
| { | ||
| sprintf( buffer , rtsp_req_resp_format , receivedCSeqNum.c_str()); | ||
| snprintf( buffer, sizeof(buffer), rtsp_req_resp_format , receivedCSeqNum.c_str()); | ||
| msg_buffer = buffer; | ||
| TEST_LOG("Response sequence number replaced as [%s]",receivedCSeqNum.c_str()); | ||
| receivedCSeqNum.clear(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -500,11 +500,22 @@ void XCastManager::registerApplications(std::vector<DynamicAppConfig*>& appConfi | |||||||||||||||||||||
| { | ||||||||||||||||||||||
| LOGINFO("Entering ..."); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| RegisterAppEntryList *appReqList = new RegisterAppEntryList; | ||||||||||||||||||||||
| RegisterAppEntryList *appReqList = new (std::nothrow) RegisterAppEntryList; | ||||||||||||||||||||||
| if (nullptr == appReqList) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| LOGERR("Failed to allocate RegisterAppEntryList"); | ||||||||||||||||||||||
| return; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| for (DynamicAppConfig* pDynamicAppConfig : appConfigList) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| RegisterAppEntry* appReq = new RegisterAppEntry; | ||||||||||||||||||||||
| RegisterAppEntry* appReq = new (std::nothrow) RegisterAppEntry; | ||||||||||||||||||||||
| if (nullptr == appReq) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| LOGERR("Failed to allocate RegisterAppEntry"); | ||||||||||||||||||||||
| delete appReqList; | ||||||||||||||||||||||
|
||||||||||||||||||||||
| delete appReqList; | |
| // Clean up previously allocated RegisterAppEntry objects | |
| if (appReqList) { | |
| while (!appReqList->empty()) { | |
| RegisterAppEntry* entry = appReqList->front(); | |
| appReqList->popFront(); | |
| delete entry; | |
| } | |
| delete appReqList; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The allocation check for
m_customQueueHandleshould occur immediately after the allocation on line 730, not at line 732 (which appears to be existing code based on the diff). The error message logged at line 733 needs to be updated to mention the allocation failure specifically.