1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <string>
17 #include <cstdlib>
18 #include <random>
19 #include <fuzzer/FuzzedDataProvider.h>
20
21 #include "deviceprofile_connector.h"
22 #include "device_profile_connector_fuzzer.h"
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 const int32_t NUMBER = 7;
DeviceProfileConnectorFuzzTest(const uint8_t * data,size_t size)27 void DeviceProfileConnectorFuzzTest(const uint8_t* data, size_t size)
28 {
29 if ((data == nullptr) || (size < sizeof(DmAccesser)) || (size < (sizeof(int32_t) * NUMBER))) {
30 return;
31 }
32
33 FuzzedDataProvider fdp(data, size);
34 std::string trustDeviceId(reinterpret_cast<const char*>(data), size);
35 std::string requestDeviceId(reinterpret_cast<const char*>(data), size);
36 std::string pkgName(reinterpret_cast<const char*>(data), size);
37 std::string trustUdid(reinterpret_cast<const char*>(data), size);
38 std::string localDeviceId(reinterpret_cast<const char*>(data), size);
39 std::string targetDeviceId(reinterpret_cast<const char*>(data), size);
40 std::string requestAccountId(reinterpret_cast<const char*>(data), size);
41 std::string deviceIdHash(reinterpret_cast<const char*>(data), size);
42 std::string trustBundleName(reinterpret_cast<const char*>(data), size);
43 DmAclInfo aclInfo;
44 aclInfo.bindType = fdp.ConsumeIntegral<int32_t>();
45 aclInfo.bindLevel = fdp.ConsumeIntegral<int32_t>();
46 aclInfo.trustDeviceId = trustDeviceId;
47 aclInfo.deviceIdHash = deviceIdHash;
48 aclInfo.authenticationType = fdp.ConsumeIntegral<int32_t>();
49 DmAccesser dmAccesser;
50 dmAccesser.requestDeviceId = requestDeviceId;
51 dmAccesser.requestUserId = fdp.ConsumeIntegral<int32_t>();
52 dmAccesser.requestAccountId = requestAccountId;
53 DmAccessee dmAccessee;
54 dmAccessee.trustDeviceId = trustDeviceId;
55 dmAccessee.trustUserId = fdp.ConsumeIntegral<int32_t>();
56 dmAccessee.trustBundleName = trustBundleName;
57 int32_t userId = fdp.ConsumeIntegral<int32_t>();
58 std::string accountId(reinterpret_cast<const char*>(data), size);
59 DmOfflineParam offlineParam;
60 DeviceProfileConnector::GetInstance().CheckBindType(trustDeviceId, requestDeviceId);
61 DeviceProfileConnector::GetInstance().GetBindTypeByPkgName(pkgName, requestDeviceId, trustUdid);
62 DeviceProfileConnector::GetInstance().GetProcessInfoFromAclByUserId(localDeviceId, targetDeviceId, userId);
63 DeviceProfileConnector::GetInstance().PutAccessControlList(aclInfo, dmAccesser, dmAccessee);
64 DeviceProfileConnector::GetInstance().UpdateAccessControlList(userId, accountId, accountId);
65 DeviceProfileConnector::GetInstance().CheckDevIdInAclForDevBind(pkgName, localDeviceId);
66 DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(localDeviceId, offlineParam);
67 DeviceProfileConnector::GetInstance().GetTrustNumber(localDeviceId);
68 }
69 }
70 }
71
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)73 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
74 {
75 /* Run your code on data */
76 OHOS::DistributedHardware::DeviceProfileConnectorFuzzTest(data, size);
77
78 return 0;
79 }