diff --git a/interfaces/innerkits/sandbox/sandbox.c b/interfaces/innerkits/sandbox/sandbox.c index 15aaf9c3b664eb1e0811bd64b84be40f3ab31ba9..02a51c514a05a1535c3212d0391067da2654c0b0 100644 --- a/interfaces/innerkits/sandbox/sandbox.c +++ b/interfaces/innerkits/sandbox/sandbox.c @@ -298,7 +298,7 @@ static void InitSandbox(sandbox_t *sandbox, const char *sandboxConfig, const cha return; } if (sandbox->isCreated) { - BEGET_LOGE("Sandbox %s has created."); + BEGET_LOGE("Sandbox %s has created.", name); return; } if (UnshareNamespace(CLONE_NEWNS) < 0) { diff --git a/services/begetctl/misc_daemon.cpp b/services/begetctl/misc_daemon.cpp index 7453af362c046cd3eedb4bca680e6a2465717732..749b5f8d989618fd4839a4a369f5c2f3c32cbde6 100755 --- a/services/begetctl/misc_daemon.cpp +++ b/services/begetctl/misc_daemon.cpp @@ -81,13 +81,13 @@ static void WriteLogoContent(int fd, const std::string &logoPath, uint32_t size) (void)fclose(rgbFile); return; } - uint32_t ret = fread(buffer, 1, size, rgbFile); - if (ret < 0) { + (void)fread(buffer, 1, size, rgbFile); + if (ferror(rgbFile)) { (void)fclose(rgbFile); free(buffer); return; } - ret = write(fd, buffer, size); + uint32_t ret = write(fd, buffer, size); if (ret != size) { (void)fclose(rgbFile); free(buffer); diff --git a/services/init/init_common_service.c b/services/init/init_common_service.c index bdb7079f3f0657a9e607807a1392af967eebd5ea..a93fd7fe140934240742c9a8d6dea053c7fb5171 100755 --- a/services/init/init_common_service.c +++ b/services/init/init_common_service.c @@ -570,7 +570,7 @@ static void ServiceTimerStartProcess(const TimerHandle handler, void *context) ServiceStopTimer(service); int ret = ServiceStart(service); if (ret != SERVICE_SUCCESS) { - INIT_LOGE("Start service \' %s \' in timer failed"); + INIT_LOGE("Start service \' %s \' in timer failed", service->name); } } diff --git a/services/init/init_group_manager.c b/services/init/init_group_manager.c index a2215e6cd99cd68b21298bf439a21a6326f3a0b9..86f8ba93ffcbbda890b931e7e576ae353267fb2f 100755 --- a/services/init/init_group_manager.c +++ b/services/init/init_group_manager.c @@ -24,7 +24,8 @@ static InitWorkspace g_initWorkspace = {0, 0, {0}, {0}, {0}}; int GenerateHashCode(const char *key) { int code = 0; - for (size_t i = 0; i < strlen(key); i++) { + size_t keyLen = strlen(key); + for (size_t i = 0; i < keyLen; i++) { code += key[i] - 'A'; } return code; diff --git a/services/init/standard/fd_holder_service.c b/services/init/standard/fd_holder_service.c index 9f46a3ab9e07e7b927bb296c1893e31b2dc82709..2777521acc70cf3d0a96b66099da3352813073dc 100644 --- a/services/init/standard/fd_holder_service.c +++ b/services/init/standard/fd_holder_service.c @@ -134,7 +134,7 @@ static void HandlerGetFds(int sock, Service *service) } if (service->fds == NULL || service->fdCount == 0) { - INIT_LOGE("Service \' %s \' does not have any held fds"); + INIT_LOGE("Service \' %s \' does not have any held fds", service->name); errorInfo = "Service without any fds"; } diff --git a/services/param/manager/param_manager.c b/services/param/manager/param_manager.c index 8a5bcecb50b381eee2ab2f4aca32ad32b5556f59..15db4f08237ec9b4b0373300e0aba23a338b38e7 100755 --- a/services/param/manager/param_manager.c +++ b/services/param/manager/param_manager.c @@ -242,10 +242,12 @@ static int CheckParamPermissionWithSelinux(const ParamSecurityLabel *srcLabel, c { static void (*setSelinuxLogCallback)(); static int (*setParamCheck)(const char *paraName, struct ucred *uc); - g_selinuxHandle = dlopen("/system/lib/libparaperm_checker.z.so", RTLD_LAZY); if (g_selinuxHandle == NULL) { - PARAM_LOGE("Failed to dlopen libparaperm_checker.z.so, %s\n", dlerror()); - return DAC_RESULT_FORBIDED; + g_selinuxHandle = dlopen("/system/lib/libparaperm_checker.z.so", RTLD_LAZY); + if (g_selinuxHandle == NULL) { + PARAM_LOGE("Failed to dlopen libparaperm_checker.z.so, %s\n", dlerror()); + return DAC_RESULT_FORBIDED; + } } if (setSelinuxLogCallback == NULL) { setSelinuxLogCallback = (void (*)())dlsym(g_selinuxHandle, "SetSelinuxLogCallback"); diff --git a/services/param/manager/param_utils.c b/services/param/manager/param_utils.c index 617baa8af28727db422d2a0c43239cde5a5dc1de..7b17b568435ddc5566b40de48bc982f8413a59ff 100755 --- a/services/param/manager/param_utils.c +++ b/services/param/manager/param_utils.c @@ -60,8 +60,9 @@ int GetSubStringInfo(const char *buff, uint32_t buffLen, char delimiter, SubStri { PARAM_CHECK(buff != NULL && info != NULL, return 0, "Invalid buff"); size_t i = 0; + size_t buffStrLen = strlen(buff); // 去掉开始的空格 - for (; i < strlen(buff); i++) { + for (; i < buffStrLen; i++) { if (!isspace(buff[i])) { break; } diff --git a/services/param/trigger/trigger_checker.c b/services/param/trigger/trigger_checker.c index bdf71a83c5729a60044e7f5c950d713cffbc6a04..cd7b29316fdc9b91de57875ee174d818f7269293 100755 --- a/services/param/trigger/trigger_checker.c +++ b/services/param/trigger/trigger_checker.c @@ -220,11 +220,12 @@ int ComputeCondition(LogicCalculator *calculator, const char *condition) PARAM_CHECK(calculator != NULL && condition != NULL, return -1, "Invalid calculator"); uint32_t currIndex = 0; uint32_t start = 0; + size_t conditionLen = strlen(condition); int noneOper = 1; CalculatorClear(calculator); LogicData data1 = {}; LogicData data2 = {}; - while (currIndex < strlen(condition)) { + while (currIndex < conditionLen) { if (condition[currIndex] == '|' || condition[currIndex] == '&') { noneOper = 0; int ret = CalculatorPop(calculator, (void*)&data2); @@ -274,10 +275,11 @@ int ConvertInfixToPrefix(const char *condition, char *prefix, uint32_t prefixLen int ret; uint32_t curr = 0; uint32_t prefixIndex = 0; + size_t conditionLen = strlen(condition); LogicCalculator calculator; CalculatorInit(&calculator, MAX_CALC_PARAM, 1, 0); - while (curr < strlen(condition)) { + while (curr < conditionLen) { if (condition[curr] == ')') { CalculatorPopChar(&calculator, &e); while (e != '(') { diff --git a/services/param/trigger/trigger_manager.c b/services/param/trigger/trigger_manager.c index f7bc8d3abfd360d3b8036de669e2800ba2715262..06600aa46b344d2131a050cbb1403805a66e2820 100755 --- a/services/param/trigger/trigger_manager.c +++ b/services/param/trigger/trigger_manager.c @@ -595,7 +595,8 @@ static int JobNodeGetNodeHasCode(const HashNode *node) { JobNode *jobNode = HASHMAP_ENTRY(node, JobNode, hashNode); int code = 0; - for (size_t i = 0; i < strlen(jobNode->name); i++) { + size_t nameLen = strlen(jobNode->name); + for (size_t i = 0; i < nameLen; i++) { code += jobNode->name[i] - 'A'; } return code; @@ -605,7 +606,8 @@ static int JobNodeGetKeyHasCode(const void *key) { int code = 0; const char *buff = (char *)key; - for (size_t i = 0; i < strlen(buff); i++) { + size_t buffLen = strlen(buff); + for (size_t i = 0; i < buffLen; i++) { code += buff[i] - 'A'; } return code; diff --git a/services/param/watcher/agent/watcher_manager_kits.cpp b/services/param/watcher/agent/watcher_manager_kits.cpp index 216d5a28eb487a838279ebcfd67d03611f963af4..2e28b1d8495218c222df5c2ba6cf60cc788e306f 100755 --- a/services/param/watcher/agent/watcher_manager_kits.cpp +++ b/services/param/watcher/agent/watcher_manager_kits.cpp @@ -135,9 +135,9 @@ int32_t WatcherManagerKits::AddWatcher(const std::string &keyPrefix, ParameterCh watcher = new ParamWatcher(keyPrefix, callback, context); WATCHER_CHECK(watcher != nullptr, return -1, "Failed to create watcher for %s", keyPrefix.c_str()); auto watcherManager = GetService(); - WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to get watcher manager"); + WATCHER_CHECK(watcherManager != nullptr, delete watcher; return -1, "Failed to get watcher manager"); uint32_t watcherId = watcherManager->AddWatcher(keyPrefix, watcher); - WATCHER_CHECK(watcherId != 0, return -1, "Failed to add watcher for %s", keyPrefix.c_str()); + WATCHER_CHECK(watcherId != 0, delete watcher; return -1, "Failed to add watcher for %s", keyPrefix.c_str()); watcher->SetWatcherId(watcherId); SetParamWatcher(keyPrefix, watcher); return watcher->GetWatcherId(); diff --git a/services/utils/init_utils.c b/services/utils/init_utils.c index 10fd7513e7d7420c820cea4f2558514d1efb0f31..2b88d3bec5703094acd10ac2e91f048ab24fd7b9 100755 --- a/services/utils/init_utils.c +++ b/services/utils/init_utils.c @@ -58,7 +58,8 @@ uid_t DecodeUid(const char *name) { INIT_CHECK_RETURN_VALUE(name != NULL, -1); int digitFlag = 1; - for (unsigned int i = 0; i < strlen(name); ++i) { + size_t nameLen = strlen(name); + for (unsigned int i = 0; i < nameLen; ++i) { if (isalpha(name[i])) { digitFlag = 0; break; diff --git a/ueventd/ueventd_read_cfg.c b/ueventd/ueventd_read_cfg.c index 7cbdcb3c029d1cb15ab6ad316b6188655b8ced29..04d90caf781a59a1e52658bf1b1ec79ca7063232 100755 --- a/ueventd/ueventd_read_cfg.c +++ b/ueventd/ueventd_read_cfg.c @@ -216,9 +216,6 @@ int ParseUeventConfig(char *buffer) static void DoUeventConfigParse(char *buffer, size_t length) { - if (length < 0) { - return; - } char **items = NULL; int count = -1; const int maxItemCount = DEFAULTITEMCOUNT;