diff --git a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c index b0c7eb0..08fa430 100644 --- a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c +++ b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c @@ -81,7 +81,8 @@ int main(int argc, char* argv[]) int ret = 0; if (argc > 1) { - if (argv[1][1] == 'c') { + // 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,8 +127,14 @@ 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)); + // 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\n"); + } 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..4195fbb 100644 --- a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c +++ b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c @@ -84,7 +84,8 @@ typedef struct { static void* asyncThreadMain(void* arg) { Controller* controller = (Controller*)arg; - usleep((controller->ack - 0.05) * 1000000); // Ack delay minus 50ms + // 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 fa52e14..daa3bf9 100644 --- a/key_simulator/IARM_BUS_UIEventSimulator.c +++ b/key_simulator/IARM_BUS_UIEventSimulator.c @@ -228,10 +228,15 @@ 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(); - /*Time being replacing scan code with 0 to run the functionality*/ - dispatcher( keyCode, keyType, 0); + // 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); + } else { + printf("%d:%s: Error: UINPUT dispatcher not available\n", __LINE__, __func__ ); + } } /**