From 06d5e22e8555425ea1c3ed5ead3ea98dbb5015f3 Mon Sep 17 00:00:00 2001 From: dkumar798_comcast Date: Wed, 3 Dec 2025 04:44:02 +0000 Subject: [PATCH 1/4] RDKEMW-11023: fix the copilot static code analysis issues --- iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c | 10 +++++++--- iarm_set_powerstate/IARM_BUS_SetPowerStatus.c | 2 +- key_simulator/IARM_BUS_UIEventSimulator.c | 8 ++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c index b0c7eb0..cc7bc93 100644 --- a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c +++ b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) int ret = 0; if (argc > 1) { - if (argv[1][1] == 'c') { + if (argv[1] && strlen(argv[1]) > 1 && argv[1][1] == 'c') { uint32_t res = 0; PowerController_PowerState_t curState = POWER_STATE_UNKNOWN, previousState = POWER_STATE_UNKNOWN; @@ -126,8 +126,12 @@ int main(int argc, char* argv[]) memset(&pwrSettings, 0, sizeof(PWRMgr_Settings_t)); if (fd > 0) { - lseek(fd, 0, SEEK_SET); - ret = read(fd, &pwrSettings, (sizeof(PWRMgr_Settings_t) - PADDING_SIZE)); + off_t seek_result = lseek(fd, 0, SEEK_SET); + if (seek_result < 0) { + printf("Error in seeking PWRMgr settings File"); + } else { + ret = read(fd, &pwrSettings, (sizeof(PWRMgr_Settings_t) - PADDING_SIZE)); + } close(fd); } diff --git a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c index c5caab5..34e61f5 100644 --- a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c +++ b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c @@ -84,7 +84,7 @@ typedef struct { static void* asyncThreadMain(void* arg) { Controller* controller = (Controller*)arg; - usleep((controller->ack - 0.05) * 1000000); // Ack delay minus 50ms + usleep(controller->ack * 1000000 - 50000); // Ack delay minus 50ms PowerController_PowerModePreChangeComplete(controller->clientId, controller->transactionId); return NULL; } diff --git a/key_simulator/IARM_BUS_UIEventSimulator.c b/key_simulator/IARM_BUS_UIEventSimulator.c index fa52e14..5cc92bc 100644 --- a/key_simulator/IARM_BUS_UIEventSimulator.c +++ b/key_simulator/IARM_BUS_UIEventSimulator.c @@ -230,8 +230,12 @@ void sendKeyEventToIARM(int keyType, int keyCode) printf("Sending Key (%x, %x) from %s\r\n", keyType, keyCode, executableName); printf("%d:%s: Using UINPUT dipatcher", __LINE__, __func__); uinput_dispatcher_t dispatcher = UINPUT_GetDispatcher(); - /*Time being replacing scan code with 0 to run the functionality*/ - dispatcher( keyCode, keyType, 0); + if (dispatcher != NULL) { + /*Time being replacing scan code with 0 to run the functionality*/ + dispatcher( keyCode, keyType, 0); + } else { + printf("%d:%s: Error: UINPUT dispatcher not available\n", __LINE__, __func__ ); + } } /** From a3886dbc23162167d5000c2548d66465f84d8295 Mon Sep 17 00:00:00 2001 From: dkumar798_comcast Date: Wed, 3 Dec 2025 06:04:38 +0000 Subject: [PATCH 2/4] RDKEMW-11023: fix the copilot static code analysis issues --- iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c | 9 ++++++--- iarm_set_powerstate/IARM_BUS_SetPowerStatus.c | 1 + key_simulator/IARM_BUS_UIEventSimulator.c | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c index cc7bc93..0b6f4e3 100644 --- a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c +++ b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c @@ -81,6 +81,7 @@ int main(int argc, char* argv[]) int ret = 0; if (argc > 1) { + // Copilot fix: Added bounds check to prevent array out-of-bounds access if (argv[1] && strlen(argv[1]) > 1 && argv[1][1] == 'c') { uint32_t res = 0; PowerController_PowerState_t curState = POWER_STATE_UNKNOWN, previousState = POWER_STATE_UNKNOWN; @@ -114,7 +115,7 @@ int main(int argc, char* argv[]) /* Dispose closes RPC conn, do not make any power manager calls after this */ PowerController_Term(); - } else if (argv[1][1] == 'h') { + } else if (argv[1] && strlen(argv[1]) > 1 && argv[1][1] == 'h') { usage(); } } else { @@ -126,10 +127,12 @@ int main(int argc, char* argv[]) memset(&pwrSettings, 0, sizeof(PWRMgr_Settings_t)); if (fd > 0) { + // Copilot fix: Added lseek error handling and ensured fd is closed in all paths + // to prevent resource leak off_t seek_result = lseek(fd, 0, SEEK_SET); if (seek_result < 0) { - printf("Error in seeking PWRMgr settings File"); - } else { + printf("Error in seeking PWRMgr settings File\n"); + } else {5 ret = read(fd, &pwrSettings, (sizeof(PWRMgr_Settings_t) - PADDING_SIZE)); } diff --git a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c index 34e61f5..3ae1de0 100644 --- a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c +++ b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c @@ -84,6 +84,7 @@ typedef struct { static void* asyncThreadMain(void* arg) { Controller* controller = (Controller*)arg; + // Copilot fix: Changed from floating-point to integer-only arithmetic to prevent overflow usleep(controller->ack * 1000000 - 50000); // Ack delay minus 50ms PowerController_PowerModePreChangeComplete(controller->clientId, controller->transactionId); return NULL; diff --git a/key_simulator/IARM_BUS_UIEventSimulator.c b/key_simulator/IARM_BUS_UIEventSimulator.c index 5cc92bc..daa3bf9 100644 --- a/key_simulator/IARM_BUS_UIEventSimulator.c +++ b/key_simulator/IARM_BUS_UIEventSimulator.c @@ -228,8 +228,9 @@ void sendKeyEventToIARM(int keyType, int keyCode) #endif printf("Sending Key (%x, %x) from %s\r\n", keyType, keyCode, executableName); - printf("%d:%s: Using UINPUT dipatcher", __LINE__, __func__); + printf("%d:%s: Using UINPUT dispatcher", __LINE__, __func__); uinput_dispatcher_t dispatcher = UINPUT_GetDispatcher(); + // Copilot fix: Added null pointer check to prevent crash when dispatcher is unavailable if (dispatcher != NULL) { /*Time being replacing scan code with 0 to run the functionality*/ dispatcher( keyCode, keyType, 0); From 5fc43bd697bb64703e8ff456d866c54a99af3c9b Mon Sep 17 00:00:00 2001 From: dkumar798_comcast Date: Wed, 3 Dec 2025 06:08:18 +0000 Subject: [PATCH 3/4] RDKEMW-11023: fix the copilot static code analysis issues --- iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c index 0b6f4e3..08fa430 100644 --- a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c +++ b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c @@ -132,7 +132,7 @@ int main(int argc, char* argv[]) off_t seek_result = lseek(fd, 0, SEEK_SET); if (seek_result < 0) { printf("Error in seeking PWRMgr settings File\n"); - } else {5 + } else { ret = read(fd, &pwrSettings, (sizeof(PWRMgr_Settings_t) - PADDING_SIZE)); } From ced821c6ee8638c174502bb46b9d5d99751e07c7 Mon Sep 17 00:00:00 2001 From: dkumar798 Date: Wed, 3 Dec 2025 12:25:08 +0530 Subject: [PATCH 4/4] RDKEMW-11023: fix the copilot static code analysis issues --- iarm_set_powerstate/IARM_BUS_SetPowerStatus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c index 3ae1de0..4195fbb 100644 --- a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c +++ b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c @@ -85,7 +85,7 @@ static void* asyncThreadMain(void* arg) { Controller* controller = (Controller*)arg; // Copilot fix: Changed from floating-point to integer-only arithmetic to prevent overflow - usleep(controller->ack * 1000000 - 50000); // Ack delay minus 50ms + usleep((controller->ack * 1000000) - 50000); // Ack delay minus 50ms PowerController_PowerModePreChangeComplete(controller->clientId, controller->transactionId); return NULL; }