1 /*
2 * Copyright (c) 2023 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 "registerdlpsandboxchangecallbackstub_fuzzer.h"
17 #include <iostream>
18 #include <string>
19 #include <thread>
20 #include <vector>
21 #include "accesstoken_kit.h"
22 #include "dlp_permission.h"
23 #include "dlp_permission_log.h"
24 #include "dlp_sandbox_change_callback.h"
25 #include "securec.h"
26 #include "token_setproc.h"
27
28 using namespace OHOS::Security::DlpPermission;
29 using namespace OHOS::Security::AccessToken;
30
31 class RegisterDlpSandboxChangeCallbackStubFuzzer : public DlpSandboxChangeCallbackCustomize {
32 public:
RegisterDlpSandboxChangeCallbackStubFuzzer()33 explicit RegisterDlpSandboxChangeCallbackStubFuzzer() {}
~RegisterDlpSandboxChangeCallbackStubFuzzer()34 ~RegisterDlpSandboxChangeCallbackStubFuzzer() override {}
35
DlpSandboxChangeCallback(DlpSandboxCallbackInfo & result)36 void DlpSandboxChangeCallback(DlpSandboxCallbackInfo& result) override {}
37 };
38
39 namespace OHOS {
FuzzTest(const uint8_t * data,size_t size)40 static void FuzzTest(const uint8_t* data, size_t size)
41 {
42 MessageParcel datas;
43 datas.WriteInterfaceToken(IDlpPermissionService::GetDescriptor());
44 std::shared_ptr<DlpSandboxChangeCallbackCustomize> callback =
45 std::make_shared<RegisterDlpSandboxChangeCallbackStubFuzzer>();
46 sptr<DlpSandboxChangeCallback> asyncStub = new (std::nothrow) DlpSandboxChangeCallback(callback);
47 if (!datas.WriteRemoteObject(asyncStub->AsObject())) {
48 return;
49 }
50 uint32_t code = static_cast<uint32_t>(DlpPermissionServiceInterfaceCode::REGISTER_DLP_SANDBOX_CHANGE_CALLBACK);
51 MessageParcel reply;
52 MessageOption option;
53 auto service = std::make_shared<DlpPermissionService>(SA_ID_DLP_PERMISSION_SERVICE, true);
54 service->OnRemoteRequest(code, datas, reply, option);
55 }
56
RegisterRegisterDlpSandboxChangeCallbackStubFuzzer(const uint8_t * data,size_t size)57 bool RegisterRegisterDlpSandboxChangeCallbackStubFuzzer(const uint8_t* data, size_t size)
58 {
59 int selfTokenId = GetSelfTokenID();
60 AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); // user_id = 100
61 SetSelfTokenID(tokenId);
62 FuzzTest(data, size);
63 SetSelfTokenID(selfTokenId);
64 return true;
65 }
66 } // namespace OHOS
67
68 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)69 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
70 {
71 /* Run your code on data */
72 OHOS::RegisterRegisterDlpSandboxChangeCallbackStubFuzzer(data, size);
73 return 0;
74 }
75