提交 a0bef945 编写于 作者: X xionglei6

init: fix codedex

Signed-off-by: Nxionglei6 <xionglei6@huawei.com>
上级 df51f3bd
...@@ -92,7 +92,7 @@ static void WriteLogToFile(FILE *fp, const char *fileName, int line, const char ...@@ -92,7 +92,7 @@ static void WriteLogToFile(FILE *fp, const char *fileName, int line, const char
char fullLogMsg[LOG_BUFFER_MAX]; char fullLogMsg[LOG_BUFFER_MAX];
if (snprintf_s(fullLogMsg, LOG_BUFFER_MAX, LOG_BUFFER_MAX - 1, "[%s:%d][%s] %s", if (snprintf_s(fullLogMsg, LOG_BUFFER_MAX, LOG_BUFFER_MAX - 1, "[%s:%d][%s] %s",
fileName == NULL ? "" : fileName, line, "fs_manager", fmt) == -1) { (fileName == NULL) ? "" : fileName, line, "fs_manager", fmt) == -1) {
return; return;
} }
(void)fprintf(fp, "%s", fullLogMsg); (void)fprintf(fp, "%s", fullLogMsg);
......
...@@ -106,8 +106,8 @@ void ReleaseFstabItem(FstabItem *item) ...@@ -106,8 +106,8 @@ void ReleaseFstabItem(FstabItem *item)
free(item->mountOptions); free(item->mountOptions);
item->mountOptions = NULL; item->mountOptions = NULL;
} }
free(item); free(item);
item = NULL;
} }
} }
...@@ -179,7 +179,7 @@ static int ParseFstabPerLine(char *str, Fstab *fstab, bool procMounts) ...@@ -179,7 +179,7 @@ static int ParseFstabPerLine(char *str, Fstab *fstab, bool procMounts)
return 0; return 0;
} while (0); } while (0);
free(item); ReleaseFstabItem(item);
item = NULL; item = NULL;
return -1; return -1;
} }
......
...@@ -44,7 +44,7 @@ static int main_cmd(int argc, char* argv[]) ...@@ -44,7 +44,7 @@ static int main_cmd(int argc, char* argv[])
printf("%s", USAGE_INFO); printf("%s", USAGE_INFO);
return 0; return 0;
} }
int ret = 0; int ret;
if (argc == REBOOT_CMD_NUMBER) { if (argc == REBOOT_CMD_NUMBER) {
ret = DoReboot(argv[1]); ret = DoReboot(argv[1]);
} else { } else {
......
...@@ -199,6 +199,9 @@ static void WriteLogoToMisc(const std::string &logoPath) ...@@ -199,6 +199,9 @@ static void WriteLogoToMisc(const std::string &logoPath)
close(fd); close(fd);
int addrOffset = (PARTITION_INFO_POS + PARTITION_INFO_MAX_LENGTH + BLOCK_SZIE_1 - 1) / BLOCK_SZIE_1; int addrOffset = (PARTITION_INFO_POS + PARTITION_INFO_MAX_LENGTH + BLOCK_SZIE_1 - 1) / BLOCK_SZIE_1;
int fd1 = open(miscDev.c_str(), O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); int fd1 = open(miscDev.c_str(), O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd1 < 0) {
return;
}
if (lseek(fd1, addrOffset * BLOCK_SZIE_1, SEEK_SET) < 0) { if (lseek(fd1, addrOffset * BLOCK_SZIE_1, SEEK_SET) < 0) {
std::cout << "Failed to seek file\n"; std::cout << "Failed to seek file\n";
close(fd1); close(fd1);
...@@ -209,10 +212,12 @@ static void WriteLogoToMisc(const std::string &logoPath) ...@@ -209,10 +212,12 @@ static void WriteLogoToMisc(const std::string &logoPath)
uint32_t size = 0; uint32_t size = 0;
if (read(fd1, &magic, sizeof(uint32_t)) != sizeof(uint32_t)) { if (read(fd1, &magic, sizeof(uint32_t)) != sizeof(uint32_t)) {
std::cout << "Failed to read magic number\n"; std::cout << "Failed to read magic number\n";
close(fd1);
return; return;
} }
if (read(fd1, &size, sizeof(uint32_t)) != sizeof(uint32_t)) { if (read(fd1, &size, sizeof(uint32_t)) != sizeof(uint32_t)) {
std::cout << "Failed to read magic number\n"; std::cout << "Failed to read magic number\n";
close(fd1);
return; return;
} }
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "init_service.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -32,6 +31,7 @@ ...@@ -32,6 +31,7 @@
#include "init_adapter.h" #include "init_adapter.h"
#include "init_cmds.h" #include "init_cmds.h"
#include "init_log.h" #include "init_log.h"
#include "init_service.h"
#include "init_service_socket.h" #include "init_service_socket.h"
#include "init_utils.h" #include "init_utils.h"
#include "securec.h" #include "securec.h"
...@@ -322,7 +322,7 @@ void ServiceReap(Service *service) ...@@ -322,7 +322,7 @@ void ServiceReap(Service *service)
} }
} }
int ret = 0; int ret;
if (service->restartArg != NULL) { if (service->restartArg != NULL) {
ret = ExecRestartCmd(service); ret = ExecRestartCmd(service);
INIT_CHECK_ONLY_ELOG(ret == SERVICE_SUCCESS, "Failed to exec restartArg for %s", service->name); INIT_CHECK_ONLY_ELOG(ret == SERVICE_SUCCESS, "Failed to exec restartArg for %s", service->name);
......
...@@ -238,7 +238,7 @@ static int GetUid(cJSON *json, uid_t *uid) ...@@ -238,7 +238,7 @@ static int GetUid(cJSON *json, uid_t *uid)
static int GetServiceGids(const cJSON *curArrItem, Service *curServ) static int GetServiceGids(const cJSON *curArrItem, Service *curServ)
{ {
int gidCount = 0; int gidCount;
cJSON *arrItem = cJSON_GetObjectItemCaseSensitive(curArrItem, GID_STR_IN_CFG); cJSON *arrItem = cJSON_GetObjectItemCaseSensitive(curArrItem, GID_STR_IN_CFG);
if (!cJSON_IsArray(arrItem)) { if (!cJSON_IsArray(arrItem)) {
gidCount = 1; gidCount = 1;
...@@ -327,7 +327,7 @@ static int AddServiceSocket(cJSON *json, Service *service) ...@@ -327,7 +327,7 @@ static int AddServiceSocket(cJSON *json, Service *service)
if (sockopt->uid == (uid_t)-1 || sockopt->gid == (uid_t)-1) { if (sockopt->uid == (uid_t)-1 || sockopt->gid == (uid_t)-1) {
free(sockopt); free(sockopt);
sockopt = NULL; sockopt = NULL;
INIT_LOGE("Invalid uid %d or gid %d", sockopt->uid, sockopt->gid); INIT_LOGE("Invalid uid or gid");
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
sockopt->passcred = false; sockopt->passcred = false;
...@@ -401,7 +401,7 @@ static int AddServiceFile(cJSON *json, Service *service) ...@@ -401,7 +401,7 @@ static int AddServiceFile(cJSON *json, Service *service)
if (fileOpt->uid == (uid_t)-1 || fileOpt->gid == (gid_t)-1) { if (fileOpt->uid == (uid_t)-1 || fileOpt->gid == (gid_t)-1) {
free(fileOpt); free(fileOpt);
fileOpt = NULL; fileOpt = NULL;
INIT_LOGE("Invalid uid %d or gid %d", fileOpt->uid, fileOpt->gid); INIT_LOGE("Invalid uid or gid");
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
fileOpt->fd = -1; fileOpt->fd = -1;
......
...@@ -38,7 +38,7 @@ static void DoExec(const struct CmdArgs *ctx) ...@@ -38,7 +38,7 @@ static void DoExec(const struct CmdArgs *ctx)
} }
if (pid == 0) { if (pid == 0) {
if (ctx == NULL || ctx->argv[0] == NULL) { if (ctx == NULL || ctx->argv[0] == NULL) {
INIT_LOGE("DoExec: invalid arguments for :%s", ctx->argv[0]); INIT_LOGE("DoExec: invalid arguments");
_exit(0x7f); _exit(0x7f);
} }
int ret = execve(ctx->argv[0], ctx->argv, NULL); int ret = execve(ctx->argv[0], ctx->argv, NULL);
......
...@@ -43,7 +43,7 @@ int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, u ...@@ -43,7 +43,7 @@ int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, u
{ {
INIT_CHECK_RETURN_VALUE((symValue != NULL) && (paramValue != NULL) && (paramLen != 0), -1); INIT_CHECK_RETURN_VALUE((symValue != NULL) && (paramValue != NULL) && (paramLen != 0), -1);
char tmpName[PARAM_NAME_LEN_MAX] = { 0 }; char tmpName[PARAM_NAME_LEN_MAX] = { 0 };
int ret = 0; int ret;
uint32_t curr = 0; uint32_t curr = 0;
char *start = (char *)symValue; char *start = (char *)symValue;
char *end = (char *)symValue + symLen; char *end = (char *)symValue + symLen;
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
int MountRequriedPartitions(const Fstab *fstab) int MountRequriedPartitions(const Fstab *fstab)
{ {
INIT_ERROR_CHECK(fstab != NULL, return -1, "Failed fstab is NULL"); INIT_ERROR_CHECK(fstab != NULL, return -1, "Failed fstab is NULL");
int rc = -1; int rc;
INIT_LOGI("Mount required partitions"); INIT_LOGI("Mount required partitions");
rc = MountAllWithFstab(fstab, 1); rc = MountAllWithFstab(fstab, 1);
return rc; return rc;
} }
\ No newline at end of file
...@@ -59,17 +59,17 @@ static int RBMiscReadUpdaterMessage(const char *path, struct RBMiscUpdateMessage ...@@ -59,17 +59,17 @@ static int RBMiscReadUpdaterMessage(const char *path, struct RBMiscUpdateMessage
INIT_CHECK_RETURN_VALUE(realPath != NULL, -1); INIT_CHECK_RETURN_VALUE(realPath != NULL, -1);
int ret = 0; int ret = 0;
FILE *fp = fopen(realPath, "rb"); FILE *fp = fopen(realPath, "rb");
free(realPath);
realPath = NULL;
if (fp != NULL) { if (fp != NULL) {
size_t readLen = fread(boot, 1, sizeof(struct RBMiscUpdateMessage), fp); size_t readLen = fread(boot, 1, sizeof(struct RBMiscUpdateMessage), fp);
(void)fclose(fp);
INIT_ERROR_CHECK(readLen > 0, ret = -1, "Failed to read misc for reboot"); INIT_ERROR_CHECK(readLen > 0, ret = -1, "Failed to read misc for reboot");
} else { } else {
ret = -1; ret = -1;
INIT_LOGE("Failed to open %s", path); INIT_LOGE("Failed to open %s", path);
} }
free(realPath);
realPath = NULL;
(void)fclose(fp);
return ret; return ret;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "init_log.h" #include "init_log.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -162,4 +163,4 @@ void InitLog(const char *outFileName, InitLogLevel logLevel, const char *kLevel, ...@@ -162,4 +163,4 @@ void InitLog(const char *outFileName, InitLogLevel logLevel, const char *kLevel,
fclose(outfile); fclose(outfile);
return; return;
} }
#endif #endif
\ No newline at end of file
...@@ -291,7 +291,7 @@ int WatcherManager::GetServerFd(bool retry) ...@@ -291,7 +291,7 @@ int WatcherManager::GetServerFd(bool retry)
do { do {
serverFd_ = socket(PF_UNIX, SOCK_STREAM, 0); serverFd_ = socket(PF_UNIX, SOCK_STREAM, 0);
int flags = fcntl(serverFd_, F_GETFL, 0); int flags = fcntl(serverFd_, F_GETFL, 0);
(void)fcntl(serverFd_, F_SETFL, flags & ~ O_NONBLOCK); (void)fcntl(serverFd_, F_SETFL, flags & ~O_NONBLOCK);
ret = ConntectServer(serverFd_, CLIENT_PIPE_NAME); ret = ConntectServer(serverFd_, CLIENT_PIPE_NAME);
if (ret == 0) { if (ret == 0) {
break; break;
......
...@@ -143,7 +143,7 @@ HWTEST_F(CmdsUnitTest, TestCommonCopy, TestSize.Level1) ...@@ -143,7 +143,7 @@ HWTEST_F(CmdsUnitTest, TestCommonCopy, TestSize.Level1)
HWTEST_F(CmdsUnitTest, TestCommonWrite, TestSize.Level1) HWTEST_F(CmdsUnitTest, TestCommonWrite, TestSize.Level1)
{ {
const char *testFile1 = "/data/init_ut/test_dir0/test_file_write1"; const char *testFile1 = "/data/init_ut/test_dir0/test_file_write1";
int fd = open(testFile1, O_RDWR | O_CREAT); int fd = open(testFile1, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
ASSERT_GE(fd, 0); ASSERT_GE(fd, 0);
DoCmdByName("write ", "/data/init_ut/test_dir0/test_file_write1 aaa"); DoCmdByName("write ", "/data/init_ut/test_dir0/test_file_write1 aaa");
...@@ -221,7 +221,7 @@ HWTEST_F(CmdsUnitTest, TestGetCmdLinesFromJson, TestSize.Level1) ...@@ -221,7 +221,7 @@ HWTEST_F(CmdsUnitTest, TestGetCmdLinesFromJson, TestSize.Level1)
cJSON *cmdsItem1 = cJSON_GetArrayItem(cmdsItem, 0); cJSON *cmdsItem1 = cJSON_GetArrayItem(cmdsItem, 0);
ASSERT_NE(nullptr, cmdsItem1); ASSERT_NE(nullptr, cmdsItem1);
CmdLines **cmdLines = (CmdLines **)calloc(1, 1); CmdLines **cmdLines = (CmdLines **)calloc(1, sizeof(CmdLines *));
ASSERT_NE(nullptr, cmdLines); ASSERT_NE(nullptr, cmdLines);
int ret = GetCmdLinesFromJson(cmdsItem1, cmdLines); int ret = GetCmdLinesFromJson(cmdsItem1, cmdLines);
EXPECT_EQ(ret, -1); EXPECT_EQ(ret, -1);
......
...@@ -49,7 +49,7 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1) ...@@ -49,7 +49,7 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
if (strncpy_s(fileOpt->fileName, strlen(fileName) + 1, fileName, strlen(fileName)) != 0) { if (strncpy_s(fileOpt->fileName, strlen(fileName) + 1, fileName, strlen(fileName)) != 0) {
free(fileOpt); free(fileOpt);
fileOpt = nullptr; fileOpt = nullptr;
ASSERT_TRUE(1); FAIL();
} }
CreateServiceFile(fileOpt); CreateServiceFile(fileOpt);
int ret = GetControlFile("/data/filetest"); int ret = GetControlFile("/data/filetest");
......
...@@ -226,6 +226,7 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1) ...@@ -226,6 +226,7 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1)
ret = SetImportantValue(service, "", invalidImportantValue, 1); ret = SetImportantValue(service, "", invalidImportantValue, 1);
EXPECT_EQ(ret, -1); EXPECT_EQ(ret, -1);
if (service != nullptr) { if (service != nullptr) {
FreeStringVector(service->pathArgs.argv, service->pathArgs.count);
free(service); free(service);
service = nullptr; service = nullptr;
} }
......
...@@ -97,7 +97,8 @@ static void TestParamTraversal() ...@@ -97,7 +97,8 @@ static void TestParamTraversal()
u_int32_t len = PARAM_BUFFER_SIZE; u_int32_t len = PARAM_BUFFER_SIZE;
SystemGetParameterValue(handle, ((char *)value) + PARAM_BUFFER_SIZE, &len); SystemGetParameterValue(handle, ((char *)value) + PARAM_BUFFER_SIZE, &len);
printf("$$$$$$$$Param %s=%s \n", (char *)value, ((char *)value) + PARAM_BUFFER_SIZE); printf("$$$$$$$$Param %s=%s \n", (char *)value, ((char *)value) + PARAM_BUFFER_SIZE);
}, nullptr); },
nullptr);
} }
static void TestPersistParam() static void TestPersistParam()
...@@ -121,10 +122,11 @@ static void TestPermission() ...@@ -121,10 +122,11 @@ static void TestPermission()
ParamSecurityOps *paramSecurityOps = &GetClientParamWorkSpace()->paramSecurityOps; ParamSecurityOps *paramSecurityOps = &GetClientParamWorkSpace()->paramSecurityOps;
paramSecurityOps->securityCheckParamPermission = TestCheckParamPermission; paramSecurityOps->securityCheckParamPermission = TestCheckParamPermission;
g_testPermissionResult = DAC_RESULT_FORBIDED; g_testPermissionResult = DAC_RESULT_FORBIDED;
GetClientParamWorkSpace()->securityLabel->flags = LABEL_CHECK_FOR_ALL_PROCESS; if ((GetClientParamWorkSpace() != nullptr) && (GetClientParamWorkSpace()->securityLabel != nullptr)) {
int ret = SystemSetParameter(testName, "22202"); GetClientParamWorkSpace()->securityLabel->flags = LABEL_CHECK_FOR_ALL_PROCESS;
EXPECT_EQ(ret, DAC_RESULT_FORBIDED); int ret = SystemSetParameter(testName, "22202");
EXPECT_EQ(ret, DAC_RESULT_FORBIDED);
}
paramSecurityOps->securityEncodeLabel = TestEncodeSecurityLabel; paramSecurityOps->securityEncodeLabel = TestEncodeSecurityLabel;
paramSecurityOps->securityDecodeLabel = TestDecodeSecurityLabel; paramSecurityOps->securityDecodeLabel = TestDecodeSecurityLabel;
paramSecurityOps->securityFreeLabel = TestFreeLocalSecurityLabel; paramSecurityOps->securityFreeLabel = TestFreeLocalSecurityLabel;
...@@ -291,4 +293,4 @@ int TestCheckParamPermission(const ParamSecurityLabel *srcLabel, const ParamAudi ...@@ -291,4 +293,4 @@ int TestCheckParamPermission(const ParamSecurityLabel *srcLabel, const ParamAudi
int TestFreeLocalSecurityLabel(ParamSecurityLabel *srcLabel) int TestFreeLocalSecurityLabel(ParamSecurityLabel *srcLabel)
{ {
return 0; return 0;
} }
\ No newline at end of file
...@@ -262,7 +262,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent) ...@@ -262,7 +262,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName, uevent->deviceName); BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName, uevent->deviceName);
} }
linkNum++; linkNum++;
if (STRINGEQUAL(parent, bootDevice)) { if ((parent != NULL) && STRINGEQUAL(parent, bootDevice)) {
BuildBootDeviceSymbolLink(links, linkNum, uevent->partitionName); BuildBootDeviceSymbolLink(links, linkNum, uevent->partitionName);
linkNum++; linkNum++;
} }
......
...@@ -85,7 +85,7 @@ int main(int argc, const char *argv[]) ...@@ -85,7 +85,7 @@ int main(int argc, const char *argv[])
if (ret) { if (ret) {
INIT_LOGE("Failed to get timeout\n"); INIT_LOGE("Failed to get timeout\n");
} else { } else {
interval = (timeoutGet > gap) ? timeoutGet - gap : 1; interval = (timeoutGet > gap) ? (timeoutGet - gap) : 1;
} }
while (1) { while (1) {
ioctl(fd, WDIOC_KEEPALIVE); ioctl(fd, WDIOC_KEEPALIVE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册