From 8b96f94c2feb6181df8011d9f5bb7dffc0413f43 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Fri, 25 Sep 2020 10:13:21 -0700 Subject: [PATCH] Updated atoi usage --- meshcore/agentcore.c | 16 +++++++++------- meshservice/ServiceMain.c | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index b41095d..5045f3e 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -2439,13 +2439,12 @@ void MeshServer_SendAgentInfo(MeshAgentHostContainer* agent, ILibWebClient_State void MeshServer_selfupdate_continue(MeshAgentHostContainer *agent) { - #ifdef WIN32 agent->performSelfUpdate = 1; #else // Set performSelfUpdate to the startupType, on Linux is this important: 1 = systemd, 2 = upstart, 3 = sysv-init int len = ILibSimpleDataStore_Get(agent->masterDb, "StartupType", ILibScratchPad, sizeof(ILibScratchPad)); - if (len > 0 && len < sizeof(ILibScratchPad)) { agent->performSelfUpdate = atoi(ILibScratchPad); } + if (len > 0 && len < sizeof(ILibScratchPad)) { ILib_atoi_int32(&(agent->performSelfUpdate), ILibScratchPad, (size_t)len); } if (agent->performSelfUpdate == 0) { agent->performSelfUpdate = 999; } // Never allow this value to be zero. #endif @@ -3145,7 +3144,10 @@ void MeshServer_OnResponse(ILibWebClient_StateObject WebStateObject, int Interru { char idleBuffer[16]; idleBuffer[ILibSimpleDataStore_Get(agent->masterDb, "controlChannelIdleTimeout", idleBuffer, sizeof(idleBuffer)-1)] = 0; - agent->controlChannel_idleTimeout_seconds = atoi(idleBuffer); + if (ILib_atoi_int32(&(agent->controlChannel_idleTimeout_seconds), idleBuffer, sizeof(idleBuffer)) == 0) + { + agent->controlChannel_idleTimeout_seconds = DEFAULT_IDLE_TIMEOUT; + } } } else @@ -4314,7 +4316,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char ** if ((len = ILibSimpleDataStore_Get(agentHost->masterDb, "enableILibRemoteLogging", ILibScratchPad, sizeof(ILibScratchPad))) != 0) { ILibScratchPad[len] = 0; - ILibStartDefaultLoggerEx(agentHost->chain, (unsigned short)atoi(ILibScratchPad), MeshAgent_MakeAbsolutePath(agentHost->exePath, ".wlg")); + ILibStartDefaultLoggerEx(agentHost->chain, ILib_atoi2_uint16(ILibScratchPad, sizeof(ILibScratchPad)), MeshAgent_MakeAbsolutePath(agentHost->exePath, ".wlg")); } #endif } @@ -4658,7 +4660,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char ** if (tmpLen > 0 && tmpLen < 16) { tmp[tmpLen] = 0; - agentHost->jsDebugPort = atoi(tmp); + agentHost->jsDebugPort = ILib_atoi2_int32(tmp, sizeof(tmp)); } } agentHost->agentMode = 1; @@ -4725,7 +4727,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char ** if (ILibSimpleDataStore_Get(agentHost->masterDb, "exitPID", NULL, 0) > 0) { int pidLen = ILibSimpleDataStore_Get(agentHost->masterDb, "exitPID", ILibScratchPad, (int)sizeof(ILibScratchPad)); - HANDLE h = OpenProcess(SYNCHRONIZE, FALSE, (DWORD)atoi(ILibScratchPad)); + HANDLE h = OpenProcess(SYNCHRONIZE, FALSE, (DWORD)ILib_atoi2_uint32(ILibScratchPad, sizeof(ILibScratchPad))); if (h != NULL) { ILibChain_AddWaitHandle(agentHost->chain, h, -1, MeshAgent_PidWaiter, agentHost); } } if (ILibSimpleDataStore_Get(agentHost->masterDb, "hideConsole", NULL, 0) > 0 && agentHost->meshCoreCtx != NULL) @@ -5092,7 +5094,7 @@ void MeshAgent_ScriptMode(MeshAgentHostContainer *agentHost, int argc, char **ar else if (strncmp(argv[i], "--script-timeout", 16) == 0 && ((i + 1) < argc)) { // Seconds before watchdog termination, 0 for unlimited - execTimeout = (unsigned int)atoi(argv[i + 1]); + execTimeout = ILib_atoi2_uint32(argv[i + 1], 255); ++i; } else if (strncmp(argv[i], "--script-connect", 16) == 0) diff --git a/meshservice/ServiceMain.c b/meshservice/ServiceMain.c index 07a9870..465fa56 100644 --- a/meshservice/ServiceMain.c +++ b/meshservice/ServiceMain.c @@ -1115,7 +1115,7 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP // Set text in the dialog box int installFlagsInt = 0; WINDOWPLACEMENT lpwndpl; - if (installFlags != NULL) { installFlagsInt = atoi(installFlags); } + if (installFlags != NULL) { installFlagsInt = ILib_atoi2_int32(installFlags, 255); } if (strnlen_s(meshid, 255) > 50) { meshid += 2; meshid[42] = 0; } if (strnlen_s(serverid, 255) > 50) { serverid[42] = 0; } SetWindowTextA(GetDlgItem(hDlg, IDC_POLICYTEXT), (meshid != NULL) ? meshname : "(None)");