!464 add fuzz permission

Merge pull request !464 from yaoyao/cherry-pick-1667034363
This commit is contained in:
openharmony_ci 2022-10-29 10:50:00 +00:00 committed by Gitee
commit ed1c491775
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 75 additions and 1 deletions

View File

@ -42,6 +42,8 @@ dtbabilitymgr_sources = [
dtbabilitymgr_external_deps = [
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"c_utils:utils",
"device_manager:devicemanagersdk",
"eventhandler:libeventhandler",
@ -71,7 +73,11 @@ ohos_fuzztest("ContinuationManagerFuzzTest") {
"-fno-omit-frame-pointer",
]
sources = [ "continuationmanager_fuzzer.cpp" ]
sources = [
"continuationmanager_fuzzer.cpp",
"mock_permission.cpp",
]
sources += dtbabilitymgr_sources
deps = [ "//foundation/ability/dmsfwk/services/base:dmsbaseinner" ]

View File

@ -21,6 +21,7 @@
#include "distributed_ability_manager_interface.h"
#include "distributed_ability_manager_stub.h"
#include "distributed_ability_manager_service.h"
#include "mock_permission.h"
namespace OHOS {
namespace DistributedSchedule {
@ -42,6 +43,7 @@ uint32_t Convert2Uint32(const uint8_t* ptr)
void FuzzUnregister(const uint8_t* rawData, size_t size)
{
DmsMockPermission::MockPermission();
uint32_t code = Convert2Uint32(rawData);
rawData = rawData + OFFSET;
size = size - OFFSET;

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mock_permission.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"
namespace OHOS {
void DmsMockPermission::MockPermission()
{
static const char *PERMS[] = {
"ohos.permission.DISTRIBUTED_DATASYNC"
};
uint64_t tokenId;
NativeTokenInfoParams infoInstance = {
.dcapsNum = 0,
.permsNum = 1,
.aclsNum = 0,
.dcaps = nullptr,
.perms = PERMS,
.acls = nullptr,
.processName = "foundation",
.aplStr = "system_core",
};
tokenId = GetAccessTokenId(&infoInstance);
SetSelfTokenID(tokenId);
}
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MOCK_PERMISSION_H
#define MOCK_PERMISSION_H
namespace OHOS {
class DmsMockPermission {
public:
static void MockPermission();
};
} // namespace OHOS
#endif // SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H