From 0dd3bd52a48fb6a05dd5c9fac71d708bf3631f22 Mon Sep 17 00:00:00 2001 From: Administrator Date: Mon, 25 May 2026 15:32:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BC=93=E5=86=B2=E5=8C=BA=E8=B6=8A?= =?UTF-8?q?=E7=95=8C=E8=AF=BB=E9=A3=8E=E9=99=A9=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MisterE Co-Authored-By: Agent --- source/dmslite_permission.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/source/dmslite_permission.c b/source/dmslite_permission.c index 9cceda7..9eeaf2d 100644 --- a/source/dmslite_permission.c +++ b/source/dmslite_permission.c @@ -101,8 +101,25 @@ int32_t CheckRemotePermission(const PermissionCheckInfo *permissionCheckInfo) return DMS_EC_GET_BUNDLEINFO_FAILURE; } /* appId: bundleName + "_" + signature */ - const char *calleeSignature = bundleInfo.appId + strlen(permissionCheckInfo->calleeBundleName) - + DELIMITER_LENGTH; + if (bundleInfo.appId == NULL || permissionCheckInfo->calleeBundleName == NULL) { + HILOGE("[Invalid appId or calleeBundleName]"); + ClearBundleInfo(&bundleInfo); + return DMS_EC_FAILURE; + } + size_t bundleNameLen = strlen(permissionCheckInfo->calleeBundleName); + size_t appIdLen = strlen(bundleInfo.appId); + if (bundleNameLen + DELIMITER_LENGTH >= appIdLen) { + HILOGE("[Invalid appId format]"); + ClearBundleInfo(&bundleInfo); + return DMS_EC_FAILURE; + } + if (strncmp(bundleInfo.appId, permissionCheckInfo->calleeBundleName, bundleNameLen) != 0 || + bundleInfo.appId[bundleNameLen] != '_') { + HILOGE("[AppId does not start with calleeBundleName_]"); + ClearBundleInfo(&bundleInfo); + return DMS_EC_FAILURE; + } + const char *calleeSignature = bundleInfo.appId + bundleNameLen + DELIMITER_LENGTH; ClearBundleInfo(&bundleInfo); if ((permissionCheckInfo->callerSignature == NULL) || (calleeSignature == NULL)) { HILOGE("[Signature is null]"); From 583590515654ff6ea25bbf8001ff918dcb5ec21e Mon Sep 17 00:00:00 2001 From: Administrator Date: Mon, 25 May 2026 16:04:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BC=93=E5=86=B2=E5=8C=BA=E8=B6=8A?= =?UTF-8?q?=E7=95=8C=E8=AF=BB=E9=A3=8E=E9=99=A9=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MisterE Co-Authored-By: Agent --- source/dmslite_permission.c | 113 ++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 49 deletions(-) diff --git a/source/dmslite_permission.c b/source/dmslite_permission.c index 9eeaf2d..8d8b2f0 100644 --- a/source/dmslite_permission.c +++ b/source/dmslite_permission.c @@ -60,6 +60,59 @@ static bool GetBmsInterface(struct BmsServerProxy **bmsInterface) } #endif +static int32_t GetCalleeBundleInfo(const char *calleeBundleName, BundleInfo *bundleInfo) +{ + int32_t errCode; +#ifndef WEARABLE_PRODUCT + uid_t callerUid = getuid(); + if (callerUid == FOUNDATION_UID) { + struct BmsServerProxy *bmsInterface = NULL; + if (!GetBmsInterface(&bmsInterface)) { + HILOGE("[GetBmsInterface query null]"); + return DMS_EC_GET_BMS_FAILURE; + } + if (calleeBundleName == NULL) { + return DMS_EC_FAILURE; + } + errCode = bmsInterface->GetBundleInfo(calleeBundleName, + GET_BUNDLE_WITHOUT_ABILITIES, bundleInfo); + } else if (callerUid == SHELL_UID) { + errCode = GetBundleInfo(calleeBundleName, GET_BUNDLE_WITHOUT_ABILITIES, bundleInfo); + } else { + errCode = EC_FAILURE; + } +#else + errCode = GetBundleInfo(calleeBundleName, GET_BUNDLE_WITHOUT_ABILITIES, bundleInfo); +#endif + if (errCode != EC_SUCCESS) { + HILOGE("[GetBundleInfo errCode = %d]", errCode); + return DMS_EC_GET_BUNDLEINFO_FAILURE; + } + return DMS_EC_SUCCESS; +} + +static int32_t ExtractCalleeSignature(const BundleInfo *bundleInfo, const char *calleeBundleName, + const char **calleeSignature) +{ + if (bundleInfo == NULL || bundleInfo->appId == NULL || calleeBundleName == NULL) { + HILOGE("[Invalid parameter]"); + return DMS_EC_FAILURE; + } + size_t bundleNameLen = strlen(calleeBundleName); + size_t appIdLen = strlen(bundleInfo->appId); + if (bundleNameLen + DELIMITER_LENGTH >= appIdLen) { + HILOGE("[Invalid appId format]"); + return DMS_EC_FAILURE; + } + if (strncmp(bundleInfo->appId, calleeBundleName, bundleNameLen) != 0 || + bundleInfo->appId[bundleNameLen] != '_') { + HILOGE("[AppId does not start with calleeBundleName_]"); + return DMS_EC_FAILURE; + } + *calleeSignature = bundleInfo->appId + bundleNameLen + DELIMITER_LENGTH; + return DMS_EC_SUCCESS; +} + int32_t CheckRemotePermission(const PermissionCheckInfo *permissionCheckInfo) { if (permissionCheckInfo == NULL) { @@ -70,65 +123,27 @@ int32_t CheckRemotePermission(const PermissionCheckInfo *permissionCheckInfo) HILOGE("[bundleInfo memset failed]"); return DMS_EC_FAILURE; } - int32_t errCode; -#ifndef WEARABLE_PRODUCT - uid_t callerUid = getuid(); - if (callerUid == FOUNDATION_UID) { - /* inner-process mode */ - struct BmsServerProxy *bmsInterface = NULL; - if (!GetBmsInterface(&bmsInterface)) { - HILOGE("[GetBmsInterface query null]"); - return DMS_EC_GET_BMS_FAILURE; - } - if (permissionCheckInfo->calleeBundleName == NULL) { - return DMS_EC_FAILURE; - } - errCode = bmsInterface->GetBundleInfo(permissionCheckInfo->calleeBundleName, - GET_BUNDLE_WITHOUT_ABILITIES, &bundleInfo); - } else if (callerUid == SHELL_UID) { - /* inter-process mode (mainly called in xts testsuit process started by shell) */ - errCode = GetBundleInfo(permissionCheckInfo->calleeBundleName, - GET_BUNDLE_WITHOUT_ABILITIES, &bundleInfo); - } else { - errCode = EC_FAILURE; + int32_t ret = GetCalleeBundleInfo(permissionCheckInfo->calleeBundleName, &bundleInfo); + if (ret != DMS_EC_SUCCESS) { + return ret; } -#else - errCode = GetBundleInfo(permissionCheckInfo->calleeBundleName, - GET_BUNDLE_WITHOUT_ABILITIES, &bundleInfo); -#endif - if (errCode != EC_SUCCESS) { - HILOGE("[GetBundleInfo errCode = %d]", errCode); - return DMS_EC_GET_BUNDLEINFO_FAILURE; - } - /* appId: bundleName + "_" + signature */ - if (bundleInfo.appId == NULL || permissionCheckInfo->calleeBundleName == NULL) { - HILOGE("[Invalid appId or calleeBundleName]"); + const char *calleeSignature = NULL; + ret = ExtractCalleeSignature(&bundleInfo, permissionCheckInfo->calleeBundleName, &calleeSignature); + if (ret != DMS_EC_SUCCESS) { ClearBundleInfo(&bundleInfo); - return DMS_EC_FAILURE; + return ret; } - size_t bundleNameLen = strlen(permissionCheckInfo->calleeBundleName); - size_t appIdLen = strlen(bundleInfo.appId); - if (bundleNameLen + DELIMITER_LENGTH >= appIdLen) { - HILOGE("[Invalid appId format]"); - ClearBundleInfo(&bundleInfo); - return DMS_EC_FAILURE; - } - if (strncmp(bundleInfo.appId, permissionCheckInfo->calleeBundleName, bundleNameLen) != 0 || - bundleInfo.appId[bundleNameLen] != '_') { - HILOGE("[AppId does not start with calleeBundleName_]"); - ClearBundleInfo(&bundleInfo); - return DMS_EC_FAILURE; - } - const char *calleeSignature = bundleInfo.appId + bundleNameLen + DELIMITER_LENGTH; - ClearBundleInfo(&bundleInfo); - if ((permissionCheckInfo->callerSignature == NULL) || (calleeSignature == NULL)) { + if (permissionCheckInfo->callerSignature == NULL || calleeSignature == NULL) { HILOGE("[Signature is null]"); + ClearBundleInfo(&bundleInfo); return DMS_EC_FAILURE; } if (strcmp(permissionCheckInfo->callerSignature, calleeSignature) != 0) { HILOGE("[Signature unmatched]"); + ClearBundleInfo(&bundleInfo); return DMS_EC_CHECK_PERMISSION_FAILURE; } + ClearBundleInfo(&bundleInfo); return DMS_EC_SUCCESS; }