From 37cef78c5b7589223d4a4ffb3fef610694e2292f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=98=BF=E9=BE=99?= <7805971+zhang_along@user.noreply.gitee.com> Date: Mon, 14 Sep 2020 16:37:08 +0800 Subject: [PATCH] Description:identityID to string Reviewed-by:yingguofeng --- include/appspawn_message.h | 2 +- src/appspawn_message.c | 20 +++++++++++++++----- src/appspawn_process.c | 4 ++-- src/appspawn_service.c | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/appspawn_message.h b/include/appspawn_message.h index 6edd3b3..8fb547f 100755 --- a/include/appspawn_message.h +++ b/include/appspawn_message.h @@ -24,7 +24,7 @@ extern "C" { typedef struct { char* bundleName; char* sharedLibPaths; - unsigned long long identityID; + char* identityID; int uID; int gID; } MessageSt; diff --git a/src/appspawn_message.c b/src/appspawn_message.c index f0741f4..d06c980 100755 --- a/src/appspawn_message.c +++ b/src/appspawn_message.c @@ -32,6 +32,8 @@ static const size_t MAX_BUNDLE_NAME_LEN = 127; static const size_t MIN_BUNDLE_NAME_LEN = 7; static const size_t MAX_SHARED_LIB_PATH_LEN = 2048; static const size_t MIN_SHARED_LIB_PATH_LEN = 0; +static const size_t MAX_IDENTITY_ID_LEN = 24; +static const size_t MIN_IDENTITY_ID_LEN = 1; void FreeMessageSt(MessageSt* targetSt) { @@ -46,7 +48,11 @@ void FreeMessageSt(MessageSt* targetSt) targetSt->sharedLibPaths = NULL; } - targetSt->identityID = 0; + if (targetSt->identityID != NULL) { + free(targetSt->identityID); + targetSt->identityID = NULL; + } + targetSt->uID = -1; targetSt->gID = -1; } @@ -120,16 +126,20 @@ int SplitMessage(const char* msg, unsigned int msgLen, MessageSt* msgSt) } cJSON* identityIDItem = cJSON_GetObjectItem(rootJ, "identityID"); + ret = ReadStringItem(identityIDItem, &(msgSt->identityID), MAX_IDENTITY_ID_LEN, MIN_IDENTITY_ID_LEN); + if (ret != EC_SUCCESS) { + FreeMessageSt(msgSt); + cJSON_Delete(rootJ); + return ret; + } + cJSON* uIDItem = cJSON_GetObjectItem(rootJ, "uID"); cJSON* gIDItem = cJSON_GetObjectItem(rootJ, "gID"); - - msgSt->identityID = (unsigned long long)ReadNumberItem(identityIDItem); msgSt->uID = (int)ReadNumberItem(uIDItem); msgSt->gID = (int)ReadNumberItem(gIDItem); cJSON_Delete(rootJ); - if (msgSt->identityID == 0 || msgSt->uID <= 0 || msgSt->gID <= 0 || - msgSt->identityID == ULLONG_MAX || msgSt->uID == INT_MAX || msgSt->gID == INT_MAX) { + if (msgSt->uID <= 0 || msgSt->gID <= 0 || msgSt->uID == INT_MAX || msgSt->gID == INT_MAX) { FreeMessageSt(msgSt); return EC_PROTOCOL; } diff --git a/src/appspawn_process.c b/src/appspawn_process.c index 902837f..31f0312 100755 --- a/src/appspawn_process.c +++ b/src/appspawn_process.c @@ -126,9 +126,9 @@ pid_t CreateProcess(const MessageSt* msgSt) return -1; } - if (sprintf_s(identityIDStr, MAX_IDENTITY_ID_LENGTH, "%llu", msgSt->identityID) <= 0 || + if (sprintf_s(identityIDStr, MAX_IDENTITY_ID_LENGTH, "%s", msgSt->identityID) <= 0 || sprintf_s(processNameStr, MAX_PROCESS_NAME_LENGTH, "%s", msgSt->bundleName) <= 0) { - HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] sprintf_s failed. id %{public}llu, name %{public}s.",\ + HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] sprintf_s failed. id %{public}s, name %{public}s.",\ msgSt->identityID, msgSt->bundleName); return -1; } diff --git a/src/appspawn_service.c b/src/appspawn_service.c index 70dd9a2..3415d9a 100755 --- a/src/appspawn_service.c +++ b/src/appspawn_service.c @@ -119,7 +119,7 @@ static int Invoke(IServerProxy* iProxy, int funcId, void* origin, IpcIo* req, Ip return EC_FAILURE; } - HILOG_INFO(HILOG_MODULE_HIVIEW, "[appspawn] msg<%{public}s,%{public}s,%{public}llu,%{public}d,%{public}d>",\ + HILOG_INFO(HILOG_MODULE_HIVIEW, "[appspawn] msg<%{public}s,%{public}s,%{public}s,%{public}d,%{public}d>",\ msgSt.bundleName, msgSt.sharedLibPaths, msgSt.identityID, msgSt.uID, msgSt.gID); pid_t newPid = CreateProcess(&msgSt); -- Gitee