未验证 提交 30ee2067 编写于 作者: O openharmony_ci 提交者: Gitee

!454 fix: 修复代码静态检查(0324)

Merge pull request !454 from 熊磊/init0324xyt
...@@ -298,7 +298,7 @@ static void InitSandbox(sandbox_t *sandbox, const char *sandboxConfig, const cha ...@@ -298,7 +298,7 @@ static void InitSandbox(sandbox_t *sandbox, const char *sandboxConfig, const cha
return; return;
} }
if (sandbox->isCreated) { if (sandbox->isCreated) {
BEGET_LOGE("Sandbox %s has created."); BEGET_LOGE("Sandbox %s has created.", name);
return; return;
} }
if (UnshareNamespace(CLONE_NEWNS) < 0) { if (UnshareNamespace(CLONE_NEWNS) < 0) {
......
...@@ -81,13 +81,13 @@ static void WriteLogoContent(int fd, const std::string &logoPath, uint32_t size) ...@@ -81,13 +81,13 @@ static void WriteLogoContent(int fd, const std::string &logoPath, uint32_t size)
(void)fclose(rgbFile); (void)fclose(rgbFile);
return; return;
} }
uint32_t ret = fread(buffer, 1, size, rgbFile); (void)fread(buffer, 1, size, rgbFile);
if (ret < 0) { if (ferror(rgbFile)) {
(void)fclose(rgbFile); (void)fclose(rgbFile);
free(buffer); free(buffer);
return; return;
} }
ret = write(fd, buffer, size); uint32_t ret = write(fd, buffer, size);
if (ret != size) { if (ret != size) {
(void)fclose(rgbFile); (void)fclose(rgbFile);
free(buffer); free(buffer);
......
...@@ -573,7 +573,7 @@ static void ServiceTimerStartProcess(const TimerHandle handler, void *context) ...@@ -573,7 +573,7 @@ static void ServiceTimerStartProcess(const TimerHandle handler, void *context)
ServiceStopTimer(service); ServiceStopTimer(service);
int ret = ServiceStart(service); int ret = ServiceStart(service);
if (ret != SERVICE_SUCCESS) { if (ret != SERVICE_SUCCESS) {
INIT_LOGE("Start service \' %s \' in timer failed"); INIT_LOGE("Start service \' %s \' in timer failed", service->name);
} }
} }
......
...@@ -24,7 +24,8 @@ static InitWorkspace g_initWorkspace = {0, 0, {0}, {0}, {0}}; ...@@ -24,7 +24,8 @@ static InitWorkspace g_initWorkspace = {0, 0, {0}, {0}, {0}};
int GenerateHashCode(const char *key) int GenerateHashCode(const char *key)
{ {
int code = 0; 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'; code += key[i] - 'A';
} }
return code; return code;
......
...@@ -142,7 +142,7 @@ static void HandlerGetFds(int sock, Service *service) ...@@ -142,7 +142,7 @@ static void HandlerGetFds(int sock, Service *service)
} }
if (service->fds == NULL || service->fdCount == 0) { 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"; errorInfo = "Service without any fds";
} }
......
...@@ -242,10 +242,12 @@ static int CheckParamPermissionWithSelinux(const ParamSecurityLabel *srcLabel, c ...@@ -242,10 +242,12 @@ static int CheckParamPermissionWithSelinux(const ParamSecurityLabel *srcLabel, c
{ {
static void (*setSelinuxLogCallback)(); static void (*setSelinuxLogCallback)();
static int (*setParamCheck)(const char *paraName, struct ucred *uc); static int (*setParamCheck)(const char *paraName, struct ucred *uc);
g_selinuxHandle = dlopen("/system/lib/libparaperm_checker.z.so", RTLD_LAZY);
if (g_selinuxHandle == NULL) { if (g_selinuxHandle == NULL) {
PARAM_LOGE("Failed to dlopen libparaperm_checker.z.so, %s\n", dlerror()); g_selinuxHandle = dlopen("/system/lib/libparaperm_checker.z.so", RTLD_LAZY);
return DAC_RESULT_FORBIDED; if (g_selinuxHandle == NULL) {
PARAM_LOGE("Failed to dlopen libparaperm_checker.z.so, %s\n", dlerror());
return DAC_RESULT_FORBIDED;
}
} }
if (setSelinuxLogCallback == NULL) { if (setSelinuxLogCallback == NULL) {
setSelinuxLogCallback = (void (*)())dlsym(g_selinuxHandle, "SetSelinuxLogCallback"); setSelinuxLogCallback = (void (*)())dlsym(g_selinuxHandle, "SetSelinuxLogCallback");
......
...@@ -60,8 +60,9 @@ int GetSubStringInfo(const char *buff, uint32_t buffLen, char delimiter, SubStri ...@@ -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"); PARAM_CHECK(buff != NULL && info != NULL, return 0, "Invalid buff");
size_t i = 0; size_t i = 0;
size_t buffStrLen = strlen(buff);
// 去掉开始的空格 // 去掉开始的空格
for (; i < strlen(buff); i++) { for (; i < buffStrLen; i++) {
if (!isspace(buff[i])) { if (!isspace(buff[i])) {
break; break;
} }
......
...@@ -220,11 +220,12 @@ int ComputeCondition(LogicCalculator *calculator, const char *condition) ...@@ -220,11 +220,12 @@ int ComputeCondition(LogicCalculator *calculator, const char *condition)
PARAM_CHECK(calculator != NULL && condition != NULL, return -1, "Invalid calculator"); PARAM_CHECK(calculator != NULL && condition != NULL, return -1, "Invalid calculator");
uint32_t currIndex = 0; uint32_t currIndex = 0;
uint32_t start = 0; uint32_t start = 0;
size_t conditionLen = strlen(condition);
int noneOper = 1; int noneOper = 1;
CalculatorClear(calculator); CalculatorClear(calculator);
LogicData data1 = {}; LogicData data1 = {};
LogicData data2 = {}; LogicData data2 = {};
while (currIndex < strlen(condition)) { while (currIndex < conditionLen) {
if (condition[currIndex] == '|' || condition[currIndex] == '&') { if (condition[currIndex] == '|' || condition[currIndex] == '&') {
noneOper = 0; noneOper = 0;
int ret = CalculatorPop(calculator, (void*)&data2); int ret = CalculatorPop(calculator, (void*)&data2);
...@@ -274,10 +275,11 @@ int ConvertInfixToPrefix(const char *condition, char *prefix, uint32_t prefixLen ...@@ -274,10 +275,11 @@ int ConvertInfixToPrefix(const char *condition, char *prefix, uint32_t prefixLen
int ret; int ret;
uint32_t curr = 0; uint32_t curr = 0;
uint32_t prefixIndex = 0; uint32_t prefixIndex = 0;
size_t conditionLen = strlen(condition);
LogicCalculator calculator; LogicCalculator calculator;
CalculatorInit(&calculator, MAX_CALC_PARAM, 1, 0); CalculatorInit(&calculator, MAX_CALC_PARAM, 1, 0);
while (curr < strlen(condition)) { while (curr < conditionLen) {
if (condition[curr] == ')') { if (condition[curr] == ')') {
CalculatorPopChar(&calculator, &e); CalculatorPopChar(&calculator, &e);
while (e != '(') { while (e != '(') {
......
...@@ -595,7 +595,8 @@ static int JobNodeGetNodeHasCode(const HashNode *node) ...@@ -595,7 +595,8 @@ static int JobNodeGetNodeHasCode(const HashNode *node)
{ {
JobNode *jobNode = HASHMAP_ENTRY(node, JobNode, hashNode); JobNode *jobNode = HASHMAP_ENTRY(node, JobNode, hashNode);
int code = 0; 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'; code += jobNode->name[i] - 'A';
} }
return code; return code;
...@@ -605,7 +606,8 @@ static int JobNodeGetKeyHasCode(const void *key) ...@@ -605,7 +606,8 @@ static int JobNodeGetKeyHasCode(const void *key)
{ {
int code = 0; int code = 0;
const char *buff = (char *)key; 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'; code += buff[i] - 'A';
} }
return code; return code;
......
...@@ -135,9 +135,9 @@ int32_t WatcherManagerKits::AddWatcher(const std::string &keyPrefix, ParameterCh ...@@ -135,9 +135,9 @@ int32_t WatcherManagerKits::AddWatcher(const std::string &keyPrefix, ParameterCh
watcher = new ParamWatcher(keyPrefix, callback, context); watcher = new ParamWatcher(keyPrefix, callback, context);
WATCHER_CHECK(watcher != nullptr, return -1, "Failed to create watcher for %s", keyPrefix.c_str()); WATCHER_CHECK(watcher != nullptr, return -1, "Failed to create watcher for %s", keyPrefix.c_str());
auto watcherManager = GetService(); 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); 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); watcher->SetWatcherId(watcherId);
SetParamWatcher(keyPrefix, watcher); SetParamWatcher(keyPrefix, watcher);
return watcher->GetWatcherId(); return watcher->GetWatcherId();
......
...@@ -58,7 +58,8 @@ uid_t DecodeUid(const char *name) ...@@ -58,7 +58,8 @@ uid_t DecodeUid(const char *name)
{ {
INIT_CHECK_RETURN_VALUE(name != NULL, -1); INIT_CHECK_RETURN_VALUE(name != NULL, -1);
int digitFlag = 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])) { if (isalpha(name[i])) {
digitFlag = 0; digitFlag = 0;
break; break;
......
...@@ -216,9 +216,6 @@ int ParseUeventConfig(char *buffer) ...@@ -216,9 +216,6 @@ int ParseUeventConfig(char *buffer)
static void DoUeventConfigParse(char *buffer, size_t length) static void DoUeventConfigParse(char *buffer, size_t length)
{ {
if (length < 0) {
return;
}
char **items = NULL; char **items = NULL;
int count = -1; int count = -1;
const int maxItemCount = DEFAULTITEMCOUNT; const int maxItemCount = DEFAULTITEMCOUNT;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册