From b1b6a655a4f021aa1182a2db7cf9151475f9ec90 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Thu, 24 Mar 2022 18:15:47 +0800 Subject: [PATCH] fix: korla review Signed-off-by: xionglei6 --- interfaces/innerkits/sandbox/sandbox.c | 2 +- services/begetctl/misc_daemon.cpp | 6 +++--- services/init/init_common_service.c | 2 +- services/init/init_group_manager.c | 3 ++- services/init/standard/fd_holder_service.c | 2 +- services/param/manager/param_manager.c | 8 +++++--- services/param/manager/param_utils.c | 3 ++- services/param/trigger/trigger_checker.c | 6 ++++-- services/param/trigger/trigger_manager.c | 6 ++++-- services/param/watcher/agent/watcher_manager_kits.cpp | 4 ++-- services/utils/init_utils.c | 3 ++- ueventd/ueventd_read_cfg.c | 3 --- 12 files changed, 27 insertions(+), 21 deletions(-) diff --git a/interfaces/innerkits/sandbox/sandbox.c b/interfaces/innerkits/sandbox/sandbox.c index 15aaf9c3..02a51c51 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 7453af36..749b5f8d 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 bdb7079f..a93fd7fe 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 a2215e6c..86f8ba93 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 9f46a3ab..2777521a 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 8a5bcecb..15db4f08 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 617baa8a..7b17b568 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 bdf71a83..cd7b2931 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 f7bc8d3a..06600aa4 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 216d5a28..2e28b1d8 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 10fd7513..2b88d3be 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 7cbdcb3c..04d90caf 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; -- GitLab