提交 c2b511ca 编写于 作者: O openharmony_ci 提交者: Gitee

!18 代码整改

Merge pull request !18 from 熊磊/appspaw3
...@@ -59,7 +59,7 @@ void FreeMessageSt(MessageSt* targetSt) ...@@ -59,7 +59,7 @@ void FreeMessageSt(MessageSt* targetSt)
} }
} }
static int ReadStringItem(cJSON* strItem, char** buf, size_t maxLen, size_t minLen) static enum OHOSLiteErrorCode ReadStringItem(cJSON* strItem, char** buf, size_t maxLen, size_t minLen)
{ {
if (strItem == NULL || !cJSON_IsString(strItem)) { if (strItem == NULL || !cJSON_IsString(strItem)) {
return EC_INVALID; return EC_INVALID;
...@@ -80,7 +80,7 @@ static int ReadStringItem(cJSON* strItem, char** buf, size_t maxLen, size_t minL ...@@ -80,7 +80,7 @@ static int ReadStringItem(cJSON* strItem, char** buf, size_t maxLen, size_t minL
return EC_NOMEMORY; return EC_NOMEMORY;
} }
if (strLength > 0 && memcpy_s(bufTmp, strLength, strPtr, strLength) != EOK) { if (strLength > 0 && memcpy_s(bufTmp, strLength + 1, strPtr, strLength) != EOK) {
free(bufTmp); free(bufTmp);
bufTmp = NULL; bufTmp = NULL;
return EC_FAILURE; return EC_FAILURE;
...@@ -117,7 +117,7 @@ static int GetCaps(const cJSON* curItem, MessageSt* msgSt) ...@@ -117,7 +117,7 @@ static int GetCaps(const cJSON* curItem, MessageSt* msgSt)
} }
if (capsCnt > MAX_CAPABILITY_COUNT) { if (capsCnt > MAX_CAPABILITY_COUNT) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] GetCaps, too many caps[cnt %{public}d], max %{public}d",\ HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] GetCaps, too many caps[cnt %{public}d], max %{public}d",
capsCnt, MAX_CAPABILITY_COUNT); capsCnt, MAX_CAPABILITY_COUNT);
return EC_INVALID; return EC_INVALID;
} }
...@@ -167,7 +167,7 @@ int SplitMessage(const char* msg, unsigned int msgLen, MessageSt* msgSt) ...@@ -167,7 +167,7 @@ int SplitMessage(const char* msg, unsigned int msgLen, MessageSt* msgSt)
} }
cJSON* bundleNameItem = cJSON_GetObjectItem(rootJ, "bundleName"); cJSON* bundleNameItem = cJSON_GetObjectItem(rootJ, "bundleName");
int ret = ReadStringItem(bundleNameItem, &(msgSt->bundleName), MAX_BUNDLE_NAME_LEN, MIN_BUNDLE_NAME_LEN); int ret = (int)ReadStringItem(bundleNameItem, &(msgSt->bundleName), MAX_BUNDLE_NAME_LEN, MIN_BUNDLE_NAME_LEN);
if (ret != EC_SUCCESS) { if (ret != EC_SUCCESS) {
FreeMessageSt(msgSt); FreeMessageSt(msgSt);
cJSON_Delete(rootJ); cJSON_Delete(rootJ);
...@@ -175,7 +175,7 @@ int SplitMessage(const char* msg, unsigned int msgLen, MessageSt* msgSt) ...@@ -175,7 +175,7 @@ int SplitMessage(const char* msg, unsigned int msgLen, MessageSt* msgSt)
} }
cJSON* identityIDItem = cJSON_GetObjectItem(rootJ, "identityID"); cJSON* identityIDItem = cJSON_GetObjectItem(rootJ, "identityID");
ret = ReadStringItem(identityIDItem, &(msgSt->identityID), MAX_IDENTITY_ID_LEN, MIN_IDENTITY_ID_LEN); ret = (int)ReadStringItem(identityIDItem, &(msgSt->identityID), MAX_IDENTITY_ID_LEN, MIN_IDENTITY_ID_LEN);
if (ret != EC_SUCCESS) { if (ret != EC_SUCCESS) {
FreeMessageSt(msgSt); FreeMessageSt(msgSt);
cJSON_Delete(rootJ); cJSON_Delete(rootJ);
......
...@@ -150,6 +150,9 @@ pid_t CreateProcess(const MessageSt* msgSt) ...@@ -150,6 +150,9 @@ pid_t CreateProcess(const MessageSt* msgSt)
#endif // OHOS_DEBUG #endif // OHOS_DEBUG
// set permissions // set permissions
if (msgSt->caps == NULL) {
exit(0x7f); // 0x7f: user specified
}
if (SetPerms(msgSt->uID, msgSt->gID, msgSt->capsCnt, msgSt->caps) != 0) { if (SetPerms(msgSt->uID, msgSt->gID, msgSt->capsCnt, msgSt->caps) != 0) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] sub-process %{public}s exit!", msgSt->bundleName); HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] sub-process %{public}s exit!", msgSt->bundleName);
exit(0x7f); // 0x7f: user specified exit(0x7f); // 0x7f: user specified
...@@ -164,7 +167,7 @@ pid_t CreateProcess(const MessageSt* msgSt) ...@@ -164,7 +167,7 @@ pid_t CreateProcess(const MessageSt* msgSt)
getpid(), errno); getpid(), errno);
} }
// 1s = 1000000000ns // 1s = 1000000000ns
long timeUsed = (tmEnd.tv_sec - tmStart.tv_sec) * 1000000000 + (tmEnd.tv_nsec - tmStart.tv_nsec); long timeUsed = (tmEnd.tv_sec - tmStart.tv_sec) * (long)1000000000 + (tmEnd.tv_nsec - tmStart.tv_nsec);
HILOG_INFO(HILOG_MODULE_HIVIEW, "[appspawn] sub-process, pid %{public}d, timeused %ld ns.",\ HILOG_INFO(HILOG_MODULE_HIVIEW, "[appspawn] sub-process, pid %{public}d, timeused %ld ns.",\
getpid(), timeUsed); getpid(), timeUsed);
#endif // OHOS_DEBUG #endif // OHOS_DEBUG
......
...@@ -85,6 +85,9 @@ static TaskConfig GetTaskConfig(Service* service) ...@@ -85,6 +85,9 @@ static TaskConfig GetTaskConfig(Service* service)
#ifdef OHOS_DEBUG #ifdef OHOS_DEBUG
static void GetCurTime(struct timespec* tmCur) static void GetCurTime(struct timespec* tmCur)
{ {
if (tmCur == NULL) {
return;
}
if (clock_gettime(CLOCK_REALTIME, tmCur) != 0) { if (clock_gettime(CLOCK_REALTIME, tmCur) != 0) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] invoke, get time failed! err %{public}d", errno); HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] invoke, get time failed! err %{public}d", errno);
} }
...@@ -93,6 +96,9 @@ static void GetCurTime(struct timespec* tmCur) ...@@ -93,6 +96,9 @@ static void GetCurTime(struct timespec* tmCur)
static int GetMessageSt(MessageSt* msgSt, IpcIo* req) static int GetMessageSt(MessageSt* msgSt, IpcIo* req)
{ {
if (msgSt == NULL || req == NULL) {
return EC_FAILURE;
}
#ifdef __LINUX__ #ifdef __LINUX__
size_t len = 0; size_t len = 0;
char* str = IpcIoPopString(req, &len); char* str = IpcIoPopString(req, &len);
...@@ -155,7 +161,7 @@ static int Invoke(IServerProxy* iProxy, int funcId, void* origin, IpcIo* req, Ip ...@@ -155,7 +161,7 @@ static int Invoke(IServerProxy* iProxy, int funcId, void* origin, IpcIo* req, Ip
GetCurTime(&tmEnd); GetCurTime(&tmEnd);
// 1s = 1000000000ns // 1s = 1000000000ns
long timeUsed = (tmEnd.tv_sec - tmStart.tv_sec) * 1000000000 + (tmEnd.tv_nsec - tmStart.tv_nsec); long timeUsed = (tmEnd.tv_sec - tmStart.tv_sec) * (long)1000000000 + (tmEnd.tv_nsec - tmStart.tv_nsec);
HILOG_INFO(HILOG_MODULE_HIVIEW, "[appspawn] invoke, reply pid %{public}d, timeused %{public}ld ns.",\ HILOG_INFO(HILOG_MODULE_HIVIEW, "[appspawn] invoke, reply pid %{public}d, timeused %{public}ld ns.",\
newPid, timeUsed); newPid, timeUsed);
#else #else
......
...@@ -208,6 +208,9 @@ HWTEST_F(StartupAppspawnUTest, msgFuncFreeTest_002, TestSize.Level1) ...@@ -208,6 +208,9 @@ HWTEST_F(StartupAppspawnUTest, msgFuncFreeTest_002, TestSize.Level1)
static void GetCurrentTime(struct timespec* tmCur) static void GetCurrentTime(struct timespec* tmCur)
{ {
if (tmCur == NULL) {
return;
}
if (clock_gettime(CLOCK_REALTIME, tmCur) != 0) { if (clock_gettime(CLOCK_REALTIME, tmCur) != 0) {
printf("[----------] StartupAppspawnUTest, get time failed! err %d.\n", errno); printf("[----------] StartupAppspawnUTest, get time failed! err %d.\n", errno);
} }
...@@ -290,11 +293,14 @@ HWTEST_F(StartupAppspawnUTest, msgFuncSplitTest_002, TestSize.Level1) ...@@ -290,11 +293,14 @@ HWTEST_F(StartupAppspawnUTest, msgFuncSplitTest_002, TestSize.Level1)
caps.push_back(1); // 1, test capability caps.push_back(1); // 1, test capability
caps.push_back(5); // 5, test capability caps.push_back(5); // 5, test capability
EXPECT_NE(msgSt.bundleName, nullptr);
EXPECT_NE(msgSt.identityID, nullptr);
EXPECT_EQ(strcmp("validName", msgSt.bundleName), 0); EXPECT_EQ(strcmp("validName", msgSt.bundleName), 0);
EXPECT_EQ(strcmp("135", msgSt.identityID), 0); EXPECT_EQ(strcmp("135", msgSt.identityID), 0);
EXPECT_EQ(TEST_UID, msgSt.uID); EXPECT_EQ(TEST_UID, msgSt.uID);
EXPECT_EQ(TEST_GID, msgSt.gID); EXPECT_EQ(TEST_GID, msgSt.gID);
EXPECT_EQ(caps.size(), msgSt.capsCnt); EXPECT_EQ(caps.size(), msgSt.capsCnt);
EXPECT_NE(msgSt.caps, nullptr);
for (size_t i = 0; i < caps.size(); ++i) { for (size_t i = 0; i < caps.size(); ++i) {
EXPECT_EQ(caps[i], msgSt.caps[i]); EXPECT_EQ(caps[i], msgSt.caps[i]);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册